//Arduino code for the Gangster puppet. We have 7 sensor values. //We also have one physical interaction, the lighting of the cigar, //which is enabled through the BlinkM and activated by the force //sensor. The BlinkM loops a script to make it gradually get //brighter and darker, simulating smoking. //Sensor pin numbers #define ELBOW 0 #define BODYX 1 #define BODYY 2 #define HEADX 3 #define HEADY 4 #define HEADZ 5 #define CIGAR 8 #define BLINKM 11 //Sensor read values float elbow = 0; float bodyX = 0; float bodyY = 0; float headX = 0; float headY = 0; float headZ = 0; float cigar = 0; float cigarLast = 0; //Addressing variables char addressChar; const char myAddress = 'G'; //Setup code void setup() { //Start listening on serial port 9600 Serial.begin(9600); //Sets the mode (input or output) for the specified pins pinMode(CIGAR, INPUT); //Reading in data from force sensor pinMode(BLINKM, OUTPUT); //Turns BlinkM on/off; the BlinkM will run a preprogrammed script when turned on }//end void setup() //Loop forever void loop() { //Read the various sensor values elbow = analogRead(ELBOW); bodyX = analogRead(BODYX); bodyY = analogRead(BODYY); headX = analogRead(HEADX); headY = analogRead(HEADY); headZ = analogRead(HEADZ); cigar = digitalRead(CIGAR); //Digital read of HIGH or LOW //Checks if Processing has sent a request for data if (Serial.available() > 0) { addressChar = char(Serial.read()); } //Checks that address is "G" if (addressChar == myAddress) { //Address matches ours, so create a reply comma-delimited message //Start message with our address Serial.print(myAddress); Serial.print(','); Serial.print(elbow); Serial.print(","); Serial.print(bodyX); Serial.print(","); Serial.print(bodyY); Serial.print(","); Serial.print(headX); Serial.print(","); Serial.print(headY); Serial.print(","); Serial.print(headZ); Serial.print(","); Serial.print(cigar); //Terminate message with newline character Serial.print('\n'); } //Reset received address addressChar = -1; //Checks if the value read from the force sensor has changed //If it has, turn the BlinkM on if force sensor is pressed, or //turn if off if the user has let go if (cigar != cigarLast) { if (cigar == HIGH) { //Power BlinkM light on digitalWrite(BLINKM, HIGH); } else { //Power BlinkM light off digitalWrite(BLINKM, LOW); } } //Set the last value from the force sensor to that currently read cigarLast = cigar; }//end void loop()