« Processing and BS2 | Main | Qtouch Capacitive Sensor »

October 26, 2004

The McVoting Booth

mcvotingbooth.jpg

Here are the BS2 and the Processing codes I used to execute my "McVoting Booth." The voting booth allowed the voter to choose between Bush or Kerry. There was a button for each candidate. The Bush button always worked (to add votes to the Bush side), but the Kerry button worked some of the time, sometimes added votes for Bush instead, and sometimes did nothing at all.

THE BS2 CODE:
********************************************************************************************

SerInPin PIN 0 'serial IN pin (RXD - at the other end: TXD)
SerOutPin PIN 1 'serial OUT pin (TXD - at the other end: RXD)
SerInData VAR BYTE 'number to match to incoming data
SerWait CON 50 'ms to wait for input before timing out
N9600 CON 16468 'BS2 baudmode values: 16468/9600, 16416/19200, 16390/38400
'See SEROUT in the Basic Stamp manual for details.


test3:
PAUSE 100

IF IN2 THEN
SEROUT SEROUTPin, N9600,[DEC 1]
DEBUG "1"
ENDIF

IF IN4 THEN
SEROUT SerOutPin, N9600,[DEC 2]
DEBUG "2"
ENDIF
GOTO test3


********************************************************************************************

PROCESSING CODE:
********************************************************************************************
// McVoting Booth
// by Kellee Santiago

// A phony voting booth that reads off of two buttons.
// votes for Bush all of the time, the other button votes for Kerry sometimes,
// Bush at others, and sometimes does nothing.

// Created 20 Oct 2004

int bushVotes = 0; //declares the variable number of bushVotes and starts it at 0
int kerryVotes = 0; //declares the variable number of kerryVotes and starts it at 0
BFont theFont; //declared the variable of the font as "theFont"
int val; //reads the value off the serial port


void setup() {
beginSerial();//starts reading the serial port
size(400,200);//screensize
theFont = loadFont("Bauhaus.vlw.gz");//declared font - make sure to copy it into project folder!
fill(255,0,0);
stroke(255);
textFont(theFont, 48);

}

void loop() {
background(255);
BImage elephant;//declare image of rep. elephant
elephant = loadImage("tease.republican.gif");//loads image - have copy in project folder!
BImage donkey;
donkey = loadImage("tease.democrat.gif");
image(elephant, 120, 50); //sets the place of the image
image(donkey, 200, 50);


smooth();//smooths out font
fill(255,0,0);
text("bush", 40,75);
text(bushVotes,65,125);
fill(0,0,255);
text("kerry", 260,75);
text(kerryVotes,285,125);
}
void serialEvent() {
val = serial;
println(val);
if(val==49) {
bushVotes++; //reads value off serial port. Processing reads in ASCII, so when the
} //serial port sends out a 1, processing sees a 49.
else
if(val==50) {
if(random(10) < 3) {
kerryVotes++;
if(random(10) > 6){
bushVotes++;
//this is how i set up a basic random generator. When processing gets a 50 (ASCII for 2)
//it randomly generates a number from 1-10. If it's less than 3, Kerry gets a vote. If it's greater
//than 6, Bush gets a vote. Nothing happens if it's 3-6.
}
}
}
}
********************************************************************************************

Posted by kellee at October 26, 2004 02:40 PM

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?