9/23/2007

i love shampoo :D







code:

// declare variables:
int switchPin = 2; // digital input pin for a switch
int redsLedPin = 3; // digital output pin for an LED
int greenLedPin = 4; // digital output pin for an LED
int whiteLedPin = 5; // digital output pin for an LED
int testLedPin = 13; // digital output pin for an LED
int switchState = 0; // the state of the switch
int counter=0;
int previousSwitchState;

void setup() {
pinMode(switchPin, INPUT); // set the switch pin to be an input
pinMode(greenLedPin, OUTPUT); // set the green LED pin to be an output
pinMode(redsLedPin, OUTPUT); // set the reds LED pin to be an output
pinMode(whiteLedPin, OUTPUT); // set the white LED pin to be an output
pinMode(testLedPin, OUTPUT);
}

void loop() {
// read the switch input:
digitalWrite(testLedPin,HIGH);
switchState = digitalRead(switchPin);
if (previousSwitchState>=switchState){
counter=counter;
}
else {
counter=counter+1;
}


if (counter==1){
digitalWrite(redsLedPin, HIGH);
digitalWrite(greenLedPin, LOW); // turn off the green LED
digitalWrite(whiteLedPin, LOW); // turn off the white LED
}
else if(counter==2){
digitalWrite(greenLedPin, HIGH);
digitalWrite(redsLedPin, HIGH); // turn off the red LED
digitalWrite(whiteLedPin, LOW); // turn on the white LED}
}
else if(counter==3){
digitalWrite(greenLedPin, HIGH);
digitalWrite(redsLedPin, HIGH); // turn off the red LED
digitalWrite(whiteLedPin, HIGH); // turn on the white LED
}
else {
digitalWrite(redsLedPin, LOW);
digitalWrite(greenLedPin, LOW); // turn off the green LED
digitalWrite(whiteLedPin, LOW); // turn off the white LED
delay(30);

}

previousSwitchState = switchState;
}

No comments: