Created
August 25, 2013 12:11
-
-
Save arduinoboard/6333537 to your computer and use it in GitHub Desktop.
The file that is currently on an Arduino Uno with a serial number of 64935343433351106102
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adafruit Arduino - Lesson 3. RGB LED | |
*/ | |
int redPin = 11; | |
int greenPin = 10; | |
int bluePin = 9; | |
const int buttonPin = 7; // the number of the pushbutton pin | |
int buttonState = 0; | |
int frq1 = 0; | |
int frq2 = 200; | |
int frq3 = 2000; | |
void setup() | |
{ | |
pinMode(redPin, OUTPUT); | |
pinMode(greenPin, OUTPUT); | |
pinMode(bluePin, OUTPUT); | |
pinMode(buttonPin, INPUT); | |
} | |
void loop() | |
{ | |
buttonState = digitalRead(buttonPin); | |
setColor(255, 0, 0); // red | |
delay(frq1); | |
setColor(0, 255, 0); // green | |
delay(frq1); | |
setColor(0, 0, 255); // blue | |
delay(frq1); | |
setColor(255, 255, 0); // yellow | |
delay(frq1); | |
setColor(80, 0, 80); // purple | |
delay(frq1); | |
setColor(0, 255, 255); // aqua | |
delay(frq1); | |
} | |
void setColor(int red, int green, int blue) | |
{ | |
if (buttonState == HIGH) { | |
frq1 = frq2; | |
analogWrite(redPin, red); | |
analogWrite(greenPin, green); | |
analogWrite(bluePin, blue); | |
} | |
else { | |
frq1= frq3; | |
analogWrite(redPin, green); | |
analogWrite(greenPin, blue); | |
analogWrite(bluePin, red); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment