//This arduino sketch blinks red, green, then blue every time the button is pressed
//Note that in this software the RGB LED has a common "anode",
//meaning the common pin goes to positive rather than negative.
//In this case HIGH turns the LED off and LOW turns it on
//In your kits, the RGB LED is common "cathode", meaning
//the common pin goes to negative (GND pin).
//This is the same sketch as before, but we are going to use variables
//in order to make it more readable.
//Here we declare the variables:
int red = 5;
int green = 6;
int blue = 7;
int button = 2;
void setup() {
pinMode(red, OUTPUT); //Instead of using numbers to refer to the LED pins,
pinMode(green, OUTPUT); //We use the variables we just declared
pinMode(blue, OUTPUT);
digitalWrite(red, HIGH); //Turn the LEDs off to start with
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
pinMode(button, INPUT_PULLUP); //The button is attached to pin 2, so we set pin 2 as input
}
void loop() {
if(digitalRead(button) == LOW) //If the button is pushed:
{
digitalWrite(red, LOW); //Turn red LED on
delay(300); //Wait 300ms
digitalWrite(red, HIGH); //Turn red LED off
digitalWrite(green, LOW); //Turn blue LED on
delay(300); //Wait 300ms
digitalWrite(green, HIGH); //Turn blue LED off
digitalWrite(blue, LOW); //Turn green LED on
delay(300); //Wait 300ms
digitalWrite(blue, HIGH); //Turn green LED off
}
}