Friday, December 4, 2009

the insult machine - electronic brick version

how it works:
on the first “insult machine”, using the potentiometer (Analog 5), the user scrolls through a list of potential 2-line insults on the 16*2 LCD (BUS 2).
the button (Analog 4) is pressed once to choose an insult.
“You have chosen insult x!”
“Tilt to send”
the button (Analog 4) is pressed again and the insult is “sent” (Digital 9 - comOut) to the 2nd “insult machine” (Digital 8 - comIn)…
“INCOMING INSULT!” flashes on the LCD (BUS 2) of the second machine, interrupting the 2nd user.
the chosen insult is then displayed on the LCD (BUS 2) of 2nd machine followed by computer laughter (HA HA HA HA in random positions alternating between the first and second row of the LCD).
both users return to scrolling through their respective insults using the potentiometers (Analog 5).
i uploaded a slight variation to each machine: machine one has 10 possible send insults and ten possible receive insults, machine 2’s libraries are reversed so the insult you receive is not in the list you have been scrolling through). i change the comebackStrings[] called up in the code and upload to the 2nd machine.
two "insult machines" connectedone "insult machine"
// include the lcd library code:
#include

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(10, 11, 12, 13, 14, 15, 16);

int tilt = 4;
int button = 4;

int comOut = 9; //initiates comunication ports at pins 8(Out) and 9(In)
int comIn = 8;

int Rot = 5;

int valRot = 0;
int valTilt = 0;
int valButton = 0;
int valNewButton = 0;
int valComeback = 0;
int valInsult = 1;
int valIn = LOW;
int comebackIn = 0;

// these constants won’t change.  But you can change the size of
// your LCD using them:
const int numRows = 2;
const int numCols = 16;

char* comebackStrings[]={“”, “Wheel turning…”, “Your village is”,
“You stand close”, “Are your parents”, “You MUST use…”, “No vaccine…”,
“Useless as…”, “No prejudice…”, “Bus leaving…”, “May your soul…”};

char* comebackStrings2[]={“”, “…hamster dead!”, “missing an idiot”,
“I hear the ocean”, “…siblings?!?”, “…birth control”, “..against stupid”,
“Popes testicles”, “…hate everyone”, “pls be under it”, “…rest in piss”};

char* comebackStrings3[]={“”, “Boring as a…”, “I dont date…”,
“Brains of 3 men”, “Does fuzzy logic”, “A closed mouth”, “Assasins do it”,
“Your gene pool”, “Death is…”, “Laugh last…”, “NO shampoo!”};

char* comebackStrings4[]={“”, “pneumatic drill”, “…other species”,
”..the 3 stooges!”, “…tickle?”, “gathers no foot”, “…from behind”,
“could use Cl2”, “hereditary”, “…think slowest”, “REAL POO!”};

void setup()
{
pinMode(comOut, OUTPUT); 
digitalWrite(comOut, LOW);
pinMode(comIn, INPUT);
lcd.begin(numRows, numCols);
Serial.begin(9600);
}

void loop()
{
lcd.clear();
delay(100);
readRot();
printComeback(); 
delay(10);
}

void readRot(){
valRot = analogRead(Rot);
delay(10);
valRot = map(valRot, 0, 1023, 1, 10);
delay(10);
checkValIn();
}

void checkButton(){
if (valButton != 1){
valButton = analogRead(button);
delay(10);
valButton = map(valButton, 0, 1023, 0, 1);
}
delay(10);
if (valButton == HIGH){
choseComeback();
}
}

void checkTilt(){
while (valTilt != 1){
valTilt = analogRead(tilt);
delay(10);
valTilt = map(valTilt, 0, 1023, 0, 1);
delay(10);
}
tiltComeback();
}

void checkValIn(){
valIn = digitalRead(comIn);
delay(10);
if (valIn == HIGH){
Serial.println(“ValIn HIGH”);
insulted();
valIn = LOW;
Serial.println(“ValIn LOW”);
}
}

void recValIn(){ 
valIn = LOW;
while (valIn == LOW){
valIn = digitalRead(comIn);
delay(10);
}
comebackIn = 0;
while (valIn != LOW){
comebackIn++;
delay(100);
valIn = digitalRead(comIn);
}
comebackIn = (comebackIn - 1);
}

void printComeback(){
while (valComeback == 0){
readRot();
lcd.clear();
lcd.print(comebackStrings[valRot]);
checkValIn();
checkButton();
delay(500);
lcd.setCursor(0, 1);
lcd.print(comebackStrings2[valRot]);
checkValIn();
checkButton();
delay(500);
checkValIn();
checkButton();
delay(500);
checkValIn();
checkButton();
delay(500);
}
}

void choseComeback(){
valComeback = valRot;
lcd.clear();
lcd.print(“You chose…”);
delay(500);
lcd.setCursor(0, 1);
lcd.print(“Insult “);
lcd.print(valRot);
lcd.print(“!”);
delay(1000);
lcd.clear();
lcd.print(“TILT to send”);
valTilt = 0;
checkTilt();
}

void tiltComeback(){
lcd.clear();
lcd.print(“TILT!”);
delay(1000);
lcd.clear();
digitalWrite(comOut, HIGH);
while (valIn != HIGH){
valIn = digitalRead(comIn);
delay(10);
}
Serial.println(“ValIn HIGH”);
digitalWrite(comOut, LOW);
Serial.println(“ComOut LOW”);
delay(1000);
digitalWrite(comOut, HIGH);
Serial.println(“ComOut HIGH”);
for (int a=0; a <= valComeback; a++){
delay(100);}
digitalWrite(comOut, LOW);
Serial.println(“ComOut LOW”);
delay(10);  
valTilt = 0;
valComeback = 0;
valButton = 0;
}

void insulted(){
digitalWrite(comOut, HIGH);
Serial.println(“ComOut HIGH”);
delay(10);
digitalWrite(comOut, LOW);
Serial.println(“ComOut LOW”);
valIn = LOW;
Serial.println(“ValIn LOW”);
recValIn();
valInsult = constrain(comebackIn, 1, 10);
lcd.clear();
lcd.print(“INCOMING INSULT!”);
delay(500);
lcd.setCursor(0, 1);
lcd.print(“INCOMING INSULT!”);
delay(500);
lcd.clear();
delay(500);
lcd.print(“INCOMING INSULT!”);
delay(500);
lcd.setCursor(0, 1);
lcd.print(“INCOMING INSULT!”);
delay(500);
lcd.clear();
lcd.print(comebackStrings3[valInsult]);
delay(500);
lcd.setCursor(0, 1);
lcd.print(comebackStrings4[valInsult]);
delay(5000);
for (int count = 0; count <= 5; count++){
lcd.clear();
lcd.setCursor(random(15), 0);
lcd.print(“HA”);
delay(200);
lcd.setCursor(random(15), 1);
lcd.print(“HA”);
delay(200);
lcd.clear();
}
}

No comments:

Post a Comment