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

void setup() {
pinMode(led1, OUTPUT);      // declare LED as output
pinMode(led2, OUTPUT);      // declare LED as output
pinMode(led3, OUTPUT);      // declare LED as output
pinMode(led4, OUTPUT);      // declare LED as output
pinMode(inputPin, INPUT);   // declare pushbutton as input
pinMode(LDRPin, INPUT);   // declare pushbutton as input
digitalWrite(led1, LOW);    // turn LED OFF
digitalWrite(led2, LOW);    // turn LED OFF
digitalWrite(led3, LOW);    // turn LED OFF
digitalWrite(led4, LOW);    // turn LED OFF
Serial.begin(300);         // opens serial port, sets data rate to 9600 bps

}

void loop(){
  intensity = analogRead(LDRPin);    // read the value from the sensor range 0 – 1024
  calibration = analogRead(inputPin);  // read input value
  Serial.println(intensity);             // Send val to the pc, can be seen using Serial Monitor
  Serial.println(calibration);       // Send val to the pc, can be seen using Serial Monitor

if (ending <= 9) {                      // resets the game when finished
counter = counter;
}
else {
counter = 1;
ending = 0;
}

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);
}
}

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s