Making Things Interactive

February 29, 2008

4: Counting Sensor Input

Filed under: 4: Counting Sensor Input — jmarshman @ 3:00 am

The counter counts to thirty in groups of ten.  The first ten presses of the switch are counted by the red light, presses 11-20 are counted by the red and green light combined, and presses 21-30 are counted by all three lights combined.  When the counter reaches 30, the three LED’s oscillate rapidly back and forth until the counter is reset at 0.     There should be video and code on here, I do not understand why. I hate wordpress.  I will consult Jerry. 

February 5, 2008

Save Energy: CLOSE THE DOOR ALREADY!

Filed under: 4: Counting Sensor Input,Brian Kish — bkish @ 10:02 pm
This is a project that utilizes a switch to tell whether a door is open or not.   It can be used on a refrigerator door or the exterior door  of your house to help  make sure that you are not wasting too much energy by leaving the door open.  When the switch is open  (meaning the door is open), the blue light starts to  flash faster and faster and it says "Door is open", as you wait longer the   green LED flashes and it says "You should close the door soon", finally the red light  flashes and tells you "CLOSE THE DOOR NOW!!  You are wasting energy".  IF the switch  is depressed (the door is closed), nothing happens and the energy fairy is happy.
Schematic of Wiring

http://www.youtube.com/watch?v=JIuhFRF08JY

/*
 *  Switch and LED test program
 */

int redLED = 9;                 // RedLED is connected to pin 9
int greenLED = 11;                // GreenLED is connected to pin 11
int blueLED = 13;                // BlueLED is connected to pin 13
int switchPin = 2;              // switch is connected to pin 2
int val;                        // variable for reading the pin status
int delayAmount = 1000;          // number of milliseconds to wait

void setup() {
  pinMode(redLED, OUTPUT);      // Set the redLED pin as output
  pinMode(greenLED, OUTPUT);    // Set the blueLED pin as output
  pinMode(blueLED, OUTPUT);     // Set the blueLED pin as output
  pinMode(switchPin, INPUT);    // Set the switch pin as input
}

void loop(){
  val = digitalRead(switchPin);    // read input value and store it in val
  if (val == HIGH) {               // check if the button is pressed
    Serial.begin(9600);
    Serial.println("The Door is Open");
    digitalWrite(blueLED, HIGH);   // turn blue LED on
    delay(1000);
    digitalWrite(blueLED, LOW);   // turn blue LED off
    delay(1000);
    digitalWrite(blueLED, HIGH);  // turn blue LED on
    delay(900);
    digitalWrite(blueLED, LOW);   // turn blue LED off
    delay(900);
    digitalWrite(blueLED, HIGH);  // turn blue LED on
    delay(600);
    digitalWrite(blueLED, LOW);   // turn blue LED off
    delay (600);
    digitalWrite(blueLED, HIGH);  // turn blue LED on
    delay (200);
    digitalWrite(blueLED, LOW);   // turn blue LED off
    delay (200);
    digitalWrite(blueLED, HIGH);  // turn blue LED on
    delay (200);
    digitalWrite(blueLED, LOW);   // turn blue LED off
    delay (200);
    Serial.begin(9600);
    Serial.println("You should close the door soon.");
    digitalWrite(greenLED, HIGH);   // turn green LED on
    delay(1000);
    digitalWrite(greenLED, LOW);   // turn green LED off
    delay(1000);
    digitalWrite(greenLED, HIGH);  // turn green LED on
    delay(900);
    digitalWrite(greenLED, LOW);   // turn green LED off
    delay(900);
    digitalWrite(greenLED, HIGH);  // turn green LED on
    delay(600);
    digitalWrite(greenLED, LOW);   // turn green LED off
    delay (600);
    digitalWrite(greenLED, HIGH);  // turn green LED on
    delay (200);
    digitalWrite(greenLED, LOW);   // turn green LED off
    delay (200);
    digitalWrite(greenLED, HIGH);  // turn green LED on
    delay (200);
    digitalWrite(greenLED, LOW);   // turn green LED off
    delay (200);
    Serial.begin(9600);
    Serial.println("CLOSE THE DOOR NOW!!! You are wasting energy!");
    digitalWrite(redLED, HIGH);   // turn red LED on
    delay(1000);
    digitalWrite(redLED, LOW);   // turn red LED off
    delay(1000);
    digitalWrite(redLED, HIGH);  // turn red LED on
    delay(900);
    digitalWrite(redLED, LOW);   // turn red LED off
    delay(900);
    digitalWrite(redLED, HIGH);  // turn red LED on
    delay(600);
    digitalWrite(redLED, LOW);   // turn red LED off
    delay (600);
    digitalWrite(redLED, HIGH);  // turn red LED on
    delay (200);
    digitalWrite(redLED, LOW);   // turn red LED off
    delay (200);
    digitalWrite(redLED, HIGH);  // turn red LED on
    delay (200);
    digitalWrite(redLED, LOW);   // turn red LED off
    delay (200);
  }
  else (val == LOW); {              // check if the button is not pressed
    digitalWrite(blueLED, LOW);    // turn blue LED off
    digitalWrite(greenLED, LOW);   // turn green LED off
    digitalWrite(redLED, LOW);     // turn red LED off
    Serial.begin(9600);
    Serial.println("The door is currently closed");
  }
  }

Roman Numeral Counter

Filed under: 4: Counting Sensor Input,Gaku Sato — ponkotsu @ 3:24 pm

I have no video cam so this will be a text-only transmission.

The following code is for a simple button-input (+1/-1) counter.

It displays the current count (0~39) in roman numerals.

Symbols (I, V, X) are represented by differently colored LEDs (8 total).

It doesn’t do subtractive notation (IX instead of VIIII) though.
The tricky points were:
– making counter wait til button is let go before looking for next input;
(otherwise +1/-1 buttons on rapidfire)
– pin 1 = transfer signal and uncontrollable?
– insufficient voltage for 8 LEDs (maybe sketchy circuitry?)
– realizing all LEDs can use same resistor to ground (and general wiring…)
– not knowing that both test LEDs were blown out…!


int PinPower = 13;

int PinUp = 11;
int PinDown = 10;

int Pin01 = 9; // pin 1 remains on…?
int Pin02 = 2;
int Pin03 = 3;
int Pin04 = 4;
int Pin05 = 5;
int Pin10 = 6;
int Pin20 = 7;
int Pin30 = 8;

int count = 0;
int letGo = 0;

int count10 = 0;
int count05 = 0;
int count01 = 0;

void setup()
{
  Serial.begin(9600);

pinMode(PinPower, OUTPUT);

pinMode(PinUp, INPUT);
  pinMode(PinDown, INPUT);

pinMode(Pin01, OUTPUT);
  pinMode(Pin02, OUTPUT);
  pinMode(Pin03, OUTPUT);
  pinMode(Pin04, OUTPUT);
  pinMode(Pin05, OUTPUT);
  pinMode(Pin10, OUTPUT);
  pinMode(Pin20, OUTPUT);
  pinMode(Pin30, OUTPUT);

digitalWrite(PinPower, HIGH);
  digitalWrite(Pin01, LOW);
  digitalWrite(Pin02, LOW);
  digitalWrite(Pin03, LOW);
  digitalWrite(Pin04, LOW);
  digitalWrite(Pin05, LOW);
  digitalWrite(Pin10, LOW);
  digitalWrite(Pin20, LOW);
  digitalWrite(Pin30, LOW);
}

void loop()
{
  if(digitalRead(PinUp)==HIGH && letGo==0)
  {
  count = count + 1;
  if(count==40) {count = 39;}
  letGo = 1;
  }
  if(digitalRead(PinDown)==HIGH && letGo==0)
  {
  count = count - 1;
  if(count==-1) {count = 0;}
  letGo = 1;
  }
  if(digitalRead(PinUp)==LOW && digitalRead(PinDown)==LOW)
  { letGo = 0; }

count10 = count/10;
  count05 = (count-10*count10)/5;
  count01 = count-10*count10-5*count05;

if(count010) {digitalWrite(Pin01, HIGH);}
  if(count011) {digitalWrite(Pin02, HIGH);}
  if(count012) {digitalWrite(Pin03, HIGH);}
  if(count013) {digitalWrite(Pin04, HIGH);}
  if(count05==0) {digitalWrite(Pin05, LOW);}
  if(count05==1) {digitalWrite(Pin05, HIGH);}
  if(count100) {digitalWrite(Pin10, HIGH);}
  if(count101) {digitalWrite(Pin20, HIGH);}
  if(count102) {digitalWrite(Pin30, HIGH);}
}

Counting with LEDs

Filed under: 4: Counting Sensor Input,Assignments,Paul Castellana — paulcastellana @ 2:35 pm

Each time you press the push button an LED lights up, and stays lit until all five are on, at which point pressing the button turns them all off, and restarts the cycle. To get it work, I manipulated the code presented at the end of the Lesson 5 LadyAda Tutorial.

int switchPin = 2;              // switch is connected to pin 2
int led1Pin = 12;
int led2Pin = 11;
int led3Pin = 10;
int led4Pin = 9;
int led5Pin = 8;

int val;                        // variable for reading the pin status
int val2;                       // variable for reading the delayed status
int buttonState;                // variable to hold the button state

int lightMode = 0;              // What mode is the light in?

void setup() {
  pinMode(switchPin, INPUT);    // Set the switch pin as input

  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(led4Pin, OUTPUT);
  pinMode(led5Pin, OUTPUT);

  Serial.begin(9600);           // Set up serial communication at 9600bps
  buttonState = digitalRead(switchPin);   // read the initial state
}

void loop(){
  val = digitalRead(switchPin);      // read input value and store it in val
  delay(10);                         // 10 milliseconds is a good amount of time
  val2 = digitalRead(switchPin);     // read the input again to check for bounces
  if (val == val2) {                 // make sure we got 2 consistant readings
    if (val != buttonState) {          // the button state has changed
      if (val == LOW) {                // check if the button is pressed
        if (lightMode == 0) {          // if its off
            lightMode = 1;               // light up 1
        } else {
          if (lightMode == 1) {        // if one's lit
              lightMode = 2;             // light up 2
          } else {
            if (lightMode == 2) {      // if 2 are lite
                lightMode = 3;           // lit up 3
            } else {
		if (lightMode == 3) {
                    lightMode = 4;
                } else {
                    if (lightMode == 4) {
                        lightMode = 5;
                    } else {
                        if (lightMode == 5) {
                            lightMode = 0;

                    }
                }
             }
           }
         }
       }
     }
   }

    buttonState = val;                 // save the new state in our variable
  }

  // Now do whatever the lightMode indicates
  if (lightMode == 0) { // all-off
    digitalWrite(led1Pin, LOW);
    digitalWrite(led2Pin, LOW);
    digitalWrite(led3Pin, LOW);
    digitalWrite(led4Pin, LOW);
    digitalWrite(led5Pin, LOW);
  }

  if (lightMode == 1) { // One on
    digitalWrite(led1Pin, HIGH);
    digitalWrite(led2Pin, LOW);
    digitalWrite(led3Pin, LOW);
    digitalWrite(led4Pin, LOW);
    digitalWrite(led5Pin, LOW);
  }

  if (lightMode == 2) { // two on
    digitalWrite(led1Pin, HIGH);
    digitalWrite(led2Pin, HIGH);
    digitalWrite(led3Pin, LOW);
    digitalWrite(led4Pin, LOW);
    digitalWrite(led5Pin, LOW);
  }

  if (lightMode == 3)  { // three on
    digitalWrite(led1Pin, HIGH);
    digitalWrite(led2Pin, HIGH);
    digitalWrite(led3Pin, HIGH);
    digitalWrite(led4Pin, LOW);
    digitalWrite(led5Pin, LOW);
  }

  if (lightMode == 4)  { // four on
    digitalWrite(led1Pin, HIGH);
    digitalWrite(led2Pin, HIGH);
    digitalWrite(led3Pin, HIGH);
    digitalWrite(led4Pin, HIGH);
    digitalWrite(led5Pin, LOW);
  }

  if (lightMode == 5)  { // five on
    digitalWrite(led1Pin, HIGH);
    digitalWrite(led2Pin, HIGH);
    digitalWrite(led3Pin, HIGH);
    digitalWrite(led4Pin, HIGH);
    digitalWrite(led5Pin, HIGH);
  }        

Arduino Event Timer

Filed under: 4: Counting Sensor Input,Joshua Smith — jssmith44 @ 1:41 pm

I wanted to write a program that would allow the Arduino to calculate the duration of an event. For instance, to be able to display how long a window has been open, or how long your dog has been lying on her pillow bed when you come home, etc. The following code is based on a simple switch with the following circuit diagram:Switch Circuit DiagramWhen the switch is put in the closed position, the Arduino begins counting seconds until the switch is opened. The seconds are then converted to “hours:minutes:seconds” format and passed back and displayed on the terminal using my displayDuration() function. Once the switch is opened, the timer is reset and can begin all over again.For the code to work correctly, I had to calibrate the program to my computer. To do this I had to calculate how many milliseconds it took my computer to process each iteration of the main loop and then set the “offSet” variable equal to that. This was mainly a trial and error process, initiating the switch at the same time as a real stopwatch and making adjustments so they matched up. 

#include 
Servo servo1; 
int ledPin = 13;

void setup() {
  servo1.attach(14);
  servo1.setMaximumPulse(2500);
  Serial.begin(19200);
  Serial.print("Ready");
}
void loop() {
  static int v = 0;
  if ( Serial.available()) {
    char ch = Serial.read();
    switch(ch) {
      case '0'...'9':
        v = v * 10 + ch - '0';
        break;
      case 's':
        servo1.write(v);
        v = 0;
        break;
        
      case 'w':
      blink();
      v = 0;
      
      
    }
  } 

 Servo::refresh();
}

void blink(){
  digitalWrite(ledPin, HIGH);   // sets the LED on
      delay(100);                  // waits for .1 second
      digitalWrite(ledPin, LOW);    // sets the LED off
      delay(100);                  // waits for .1 second
    }

Photosensor

Filed under: 4: Counting Sensor Input,Tiffany Yang — tyang1 @ 8:49 am

Since my project has to do with light in a night table, I thought the first step would be to use a photosensor. When light is detected, my arduino will say good night.


int ledPin = 13;                //sets LEDs to pin 13
int photoPin = 0;               //photoresistor connected to Analog 0
int light;                      //variable for reading photosensor
int photoState;                 //variable to hold the state of the sensor
int lightPresses;               //how many times the light is turned off or on

void setup() {
  pinMode(ledPin, OUTPUT);             //set the ledPin as an Output
  Serial.begin(9600);                  //set up Serial Library at 9600 bps
  pinMode(photoPin, INPUT);            //sets photoresistor as INPUT
  photoState = analogRead(photoPin);   //read the initial state of photosensor
}  

void loop() {
  light = analogRead(photoPin);        // reads resistance from the sensor
  if (light != photoState) {
    if (light <= 500) {                  //if there is no light
      digitalWrite(ledPin, HIGH);          // LEDs turn on
      lightPresses++;
      Serial.print("Goodnight for the ");
      Serial.print(lightPresses);
      Serial.println("th times");
      delay(1000);
    }
    else {                               //if there is light
      digitalWrite(ledPin, LOW);         //LEDs are off
      Serial.println("Goodmorning");
      delay(1000);
    }
  }
  photoState = light;
} 

Assignment 4, Counting Sensor

Filed under: 4: Counting Sensor Input,Siddartha Butalia — sbutalia @ 4:20 am

with this assignment i wanted to explore output options more as im going to be diving into different sensor inputs for my projects. lights tend to be interesting so I wanted to experiment with differnt ways of outputting actions with lights. My output is a series of growing and fading LEDs which are dependant on how long you hold down the switch for. I still have a counter which adds up the total number of button presses and keeps track of it.

[ youtube=http://www.youtube.com/watch?v=VKqE7xAhVAA ]

Link to Video

Here is the code:

int switchPin = 2;              // Switch connected to digital pin 2
int count = 0;                  // Counter
int ledPin = 13;                // test pin
int flag = 0;                   // variable to check for holding of the button
void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);           // set up Serial library at 9600 bps
  pinMode(switchPin, INPUT);    // sets the digital pin as input to read switch
  for (int i=8; i  1){                      // the fancy LED output
    analogWrite(8, 15);
    if (flag > 2){
      analogWrite(8,255);
      if (flag > 3){
        analogWrite(9, 15);
        if (flag > 4){
          analogWrite(9,255);
          if (flag > 5){
            analogWrite(10,15);
            if (flag > 6){
              analogWrite(10,255);
              if (flag > 7) {
                analogWrite(11,15);
                if (flag > 8 ) {
                  analogWrite(11,255);
                }
              }
            }
          }
        }
      }
    }
  }
  Serial.println(count);       // used to check the accuracy of the counter
  delay(100);
  digitalWrite(ledPin,LOW);
  if(flag < 2){     digitalWrite(11,LOW);     delay(50);     digitalWrite(10,LOW);     delay(50);     digitalWrite(9,LOW);     delay(50);     digitalWrite(8,LOW);   } }[/sourcecode] and i have no idea why my youtube thing wont work or why this wordpress link keeps coming inside my sourcecode

First Time Using Infrared Sensor

Filed under: 4: Counting Sensor Input,Assignments,Lingshui Wang — lingshui @ 1:20 am

So I ordered a proximity infrared sensor from electronics 123 for this, and it’s given me many headaches – both in the wiring and coding stages. It took me about 3 hours to figure out that the IR sensor only had a high low function rather than variable resistance, and that the sensor had a 3 second delay when used with my own body heat. Anyways, this is just a simple circuit with an infrared sensor attached to 3 lights that blink in 3 different modes (keep in mind that the sensor has a 3 second delay when triggered, so there is a pause when the light changes, I’ve been trying to figure out if there is a way to fix this…). Anyways, here is a video and the sourcecode.

int IRSwitch = 0;                       //infrared switch set to analog 0
int light1 = 10;                        //lights 1 through 3 set to digitals 10 through 12
int light2 = 11;
int light3 = 12;
int val;
int val2;
int buttonState;
int lightMode = 0;

void setup()
  {
    Serial.begin(9600);                  //serial library set at 9600
    pinMode(IRSwitch, INPUT);            //infrared switch set to input
    pinMode(light1, OUTPUT);             //lights 1 through 3 set to output
    pinMode(light2, OUTPUT);
    pinMode(light3, OUTPUT);
    buttonState = analogRead(IRSwitch);
  }

void loop(){
  val = analogRead(IRSwitch);            // read input value and store it in val
  delay(10);
  val2 = analogRead(IRSwitch);
  Serial.print("Read switch input: ");   //serial library keeps track of switch function
  Serial.println(analogRead(IRSwitch));
  delay(100);
  if (val == val2) {                     //sensor check
    if (val != buttonState) {
      if (val == 0) {                    // check if the button is pressed
        if (lightMode == 0) {            // if in mode 0
          lightMode = 1;                 // switch to mode 1
        } else {
          if (lightMode == 1) {          //in in mode 1
            lightMode = 2;               //switch to mode 2
          } else {
            if (lightMode == 2) {        //if in mode 2
              lightMode = 3;             //switch to mode 3
            } else {
	      if (lightMode == 3) {      	 //if in mode 3
                lightMode = 0;           //switch to mode 0
              }
			}
          }
        }
      }
    }
    buttonState = val;                   // save state in variable
  }
                if (lightMode == 0) {    //lightmode 0
                  digitalWrite(light1, LOW);
                  digitalWrite(light2, LOW);
                  digitalWrite(light3, LOW);
                }

                if (lightMode == 1) {    //lightmode 1
                  digitalWrite(light1, HIGH);
                  digitalWrite(light2, HIGH);
                  digitalWrite(light3, HIGH);
                }

                if (lightMode == 2) {    //lightmode 2
                  digitalWrite(light1, HIGH);
                  digitalWrite(light2, LOW);
                  digitalWrite(light3, LOW);
                  delay(100);
                  digitalWrite(light1, LOW);
                  digitalWrite(light2, HIGH);
                  digitalWrite(light3, LOW);
                  delay(100);
                  digitalWrite(light1, LOW);
                  digitalWrite(light2, LOW);
                  digitalWrite(light3, HIGH);
                  delay(100);
                  digitalWrite(light1, LOW);
                  digitalWrite(light2, HIGH);
                  digitalWrite(light3, LOW);
                  delay(100);
                  digitalWrite(light1, HIGH);
                  digitalWrite(light2, LOW);
                  digitalWrite(light3, LOW);
                  delay(100);
                }

                if (lightMode == 3) {    //lightmode 3
                  digitalWrite(light1, HIGH);
                  digitalWrite(light2, HIGH);
                  digitalWrite(light3, LOW);
                  delay(100);
                  digitalWrite(light1, LOW);
                  digitalWrite(light2, HIGH);
                  digitalWrite(light3, HIGH);
                  delay(100);
                  digitalWrite(light1, HIGH);
                  digitalWrite(light2, LOW);
                  digitalWrite(light3, HIGH);
                  delay(100);
                }
                }

Binary Counter

Filed under: 4: Counting Sensor Input,Lea — tovelet @ 12:32 am

I made a binary counter, that displays the number of button presses with four green LEDs, because I wanted to see if I could figure out a simple way of coding it. My answer uses the modulus function.

/*
 * Binary Blink
 *
 * Four LEDs as a counting display
 *
 */


int onesPlace = 12;                // 
int twosPlace = 11;                // 
int foursPlace = 10;               // 
int eightsPlace = 9;               // Pins for ones through eights places
int switchPin = 2;                 // Pin for switch
int n = 0;                         // Number of clicks
int buttonPress = 1;               // Will change when button is pressed


void setup()                       // run once, when the sketch starts
{
  pinMode(onesPlace, OUTPUT);
  pinMode(twosPlace, OUTPUT); 
  pinMode(foursPlace, OUTPUT);
  pinMode(eightsPlace, OUTPUT);     // sets the LED pins as output
  pinMode(switchPin, INPUT);
  Serial.begin(9600);               // for feedback that "n" is correct
}

void loop()                         // run over and over again
{
if (digitalRead(switchPin) == HIGH) {buttonPress = 0;}
if (digitalRead(switchPin) == LOW && buttonPress == 0) // only if the button has been pushed and released
    {
      n++;                          // increment "n"
      digitalWrite(onesPlace, n % 2);
      digitalWrite(twosPlace, (n / 2) % 2);
      digitalWrite(foursPlace, (n / 4) % 2);
      digitalWrite(eightsPlace, (n / 8 ) % 2);
      Serial.println(n);            // tell me what "n" is
      buttonPress = 1;              // don't do anything until another button press
    }
}

I did all of the coding without testing, unfortunately, because I’d left my Arduino elsewhere. I also drew a quick wiring diagram, so I’d be able to put my breadboard together relatively quickly once I had the components.


Once I figured out the right direction for the DPST switch, the counter worked, surprisingly smoothly. The only glitch is that the counter occasionally skips forward quickly during a button press, and I think that is the switch malfunctioning, or a loose contact.

Switch/Counter 3 Way Light

Filed under: 4: Counting Sensor Input,Assignments,Christopher Bridgman — cbridgma @ 12:32 am

So, originally, I wanted to do this with a tilt sensor, but due to time, I was unable to get one. So what I did was create a switch that would toggle between 4 different light settings. I could imagine taking a light with a tilt sensor and programming this to light up each mode to a different angle (this kicked my butt enough!) I know to some people, this would be easy, but I had a hard time. It was really only because i tried doing it on my own instead of trying to look things up on the Ladyada site. That did wonders for me. But any way. Here is a video of the final product and code.



int redPin = 12;                  // Red LED connected to digital pin 12
int greenPin = 11;                // Green LED connected to digital pin 11
int bluePin = 10;                   // Blue LED connected to digital pin 10
int switchPin = 9;                   // Swtitch Connected to digital pin 9                        
int val;
int val2;
int buttonState;
int lightMode = 0;

void setup()                      // run once, when the sketch starts
{
  pinMode(redPin, OUTPUT);        // sets the digital pin as output
  pinMode(greenPin, OUTPUT);      // sets the digital pin as output
  pinMode(bluePin, OUTPUT);       // sets the digital pin as output
  pinMode(switchPin, INPUT);      // sets the digital pin as input
  
  buttonState = digitalRead(switchPin);
}

void loop()                       // run over and over again
{
  val = digitalRead(switchPin); //Read the pin
  delay(10);
  val2 = digitalRead(switchPin);
  if (val == val2)
  {
    if (val !=buttonState)
    {
      if (val == LOW)
      {
        if (lightMode == 0) {          // if its off
          lightMode = 1;               // turn red light on
        } else {
          if (lightMode == 1) {        // if red light on
            lightMode = 2;             // turn green light on
          } else {
            if (lightMode == 2) {      // if green light on
              lightMode = 3;           // turn blue light on
            } else {
			  if (lightMode == 3) { //  if blue light on 
                lightMode = 0;           // turn light off!

}}}}}}
        buttonState = val;
}
  if (lightMode == 0) {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
  }
  
 
  if (lightMode == 1) {
    digitalWrite(redPin, HIGH);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
  }


  if (lightMode == 2) {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);
    digitalWrite(bluePin, LOW);
  
  
  }
  if (lightMode == 3) {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, HIGH);
  }
}
Next Page »

Blog at WordPress.com.