criticalmaking.com

Alone in the lab… with thoughts of digital democracy!

February 26, 2009inf2241_classfi22411

// Wiring / Arduino Code
// Code for sensing a switch status and writing the value to the serial port.
int switchPin = 7;                       // Switch connected to pin 7
int ledPin = 13;
int val=0;
void setup() {
pinMode(switchPin, INPUT);             // Set pin 0 as an input
Serial.begin(9600);                    // Start serial communication at 9600 bps
pinMode (ledPin, OUTPUT);
}
void loop() {
if (digitalRead(switchPin) == HIGH) {  // If switch is ON,
Serial.print(1, BYTE);               // send 1 to Processing
} else {                               // If the switch is not ON,
Serial.print(0, BYTE);               // send 0 to Processing
}
delay(100);                            // Wait 100 milliseconds
val = digitalRead(switchPin);  // read input value
if (val == HIGH) {         // check if the input is HIGH (button released)
digitalWrite(ledPin, HIGH);  // turn LED OFF
} else {
digitalWrite(ledPin, LOW);  // turn LED ON
}
}

// VOTING MACHINE VISUAL INTERFACE
import processing.serial.*;
Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port
int vote = 0;  //Vote status
int t = 0;
int pause = 0;
String dude = “OBAMA!”;
PImage obama;
PImage latour;
PImage nathaniel;
PFont font;
void setup() {
size(600, 300);
String portName = “COM3”;
myPort = new Serial(this, portName, 9600);
noStroke();
fill(0);    // Set fill to black
font = loadFont(“Arial-Black-24.vlw”);
textFont (font);
textAlign(CENTER);
}
void draw() {
if ( myPort.available() > 0) {  // If data is available,
val = myPort.read();         // read it and store it in val
}
background(255);             // Set background to white
text(“VOTE”,300,50);
obama = loadImage(“obama.jpg”);
image(obama,100,75);
latour = loadImage(“latour.jpg”);
image(latour,250,75);
nathaniel = loadImage(“nathaniel.jpg”);
image(nathaniel,400,75);
fill (0);
rect(50, 225, 25+t, 25);
if (val == 0) {  // If the serial value is 0 (button released)
if (vote == 1) {    // If vote has been registered
background (0);

if (t > 000) {dude = “OBAMA!”;

if (t > 200) dude = “BRUNO!”;

if (t > 400) dude = “NATHANIEL??”;
fill (255);
text(dude,300,150);
vote = 0;
t = 0;
pause = 2000;
}
delay (pause);
} else {      // If the serial value is not 0 (button pressed)
pause = 0;
vote = 1;
t = t + 10;
if (t >= 450) t = 0;  // Return to beginning
}
}

//BBB

You can follow any responses to this entry through the RSS feed. You can leave a response, or trackback from your own site.

One Comment

  1. nutsMarch 2, 2009 at 8:50 pm

    Excellent example of a biased voting machine. Nice voting box that you have created there!!!

Leave a reply

Follow Us