Class blog for CMU’s Making Things Interactive, Fall, 2008

Post navigation

Gaming Sweater

The gaming jacket recieves “IR” signals that are triggers in an interactive game. A potentiometer controls the sensitivity of the sensor and, therefore, the difficulty level of the game. For the in class demo an LDR was used in place of IR.

/*
* Gaming Sweater
* by Jason Read
*
*/

int LDRPin = 3; // pin for the LDR
int led1 = 9; // choose the pin for the LED
int led2 = 10; // choose the pin for the LED
int led3 = 11; // choose the pin for the LED
int led4 = 12; // choose the pin for the LED
int inputPin = 5; // input pin for potentiometer
int intensity = 0; // variable for reading LDR
int calibration = 0; // variable for reading Pot
int counter = 0; // store the number of button presses
int ending = 0; // resets the game
boolean buttonDown = false; // a flag that stores if the button is beeing pressed down or not
boolean isLightOn = false; // a flag that stores if the led is on or off

if (intensity <= calibration && buttonDown == false) { // check if the input is HIGH and the button is not already been held down
buttonDown = true; // set the button flag to down
counter = counter +1; // add one to the counter
}

//if we are no longer pressing the button down set the buttonDown flag to up
if (intensity >= calibration){
buttonDown = false; // set the buttonDown value to up
}

if (counter == 2) // one trigger activated
{
digitalWrite(led1,HIGH);
}
else if (counter == 3) // second trigger activated
{
digitalWrite(led2,HIGH);
}
else if (counter == 4) // third trigger activated
{
digitalWrite(led3,HIGH);
}
else if (counter >= 5) // final trigger activated, game won
{
digitalWrite(led1, HIGH); // sets the LED on
digitalWrite(led2, LOW); // sets the LED off
digitalWrite(led3, LOW); // sets the LED off
delay(100); // waits for a second
digitalWrite(led1, LOW); // sets the LED on
digitalWrite(led2, HIGH); // sets the LED off
digitalWrite(led3, LOW); // sets the LED off
delay(100); // waits for a second
digitalWrite(led1, LOW); // sets the LED on
digitalWrite(led2, LOW); // sets the LED off
digitalWrite(led3, HIGH); // sets the LED off
delay(100);
digitalWrite(led1, LOW); // sets the LED on
digitalWrite(led2, LOW); // sets the LED off
digitalWrite(led3, LOW); // sets the LED off
ending = ending +1; // add one to the finishing counter
delay(80);
}
else
{
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
}
}