42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
/*
|
|
RGB Blink
|
|
Alternates R, G and B LED on for one second, then off for one second, repeatedly.
|
|
The frequency depends on the position of the potentiometer.
|
|
|
|
This example code is in the public domain.
|
|
|
|
modified 20 May 2016
|
|
by Shawn Nock
|
|
*/
|
|
|
|
#define RED 3
|
|
#define GREEN 4
|
|
#define BLUE 5
|
|
|
|
int delay_ms = 1000; // How long to keep LEDs on and off in milliseconds (sec/1000)
|
|
|
|
// the setup function runs once when you press reset or power the board
|
|
void setup() {
|
|
// initialize digital pin 13 as an output.
|
|
pinMode(RED, OUTPUT);
|
|
pinMode(GREEN, OUTPUT);
|
|
pinMode(BLUE, OUTPUT);
|
|
}
|
|
|
|
// the loop function runs over and over again forever
|
|
void loop() {
|
|
delay_ms = analogRead(A0);
|
|
digitalWrite(RED, HIGH); // turn the LED on (HIGH is the voltage level)
|
|
delay(delay_ms); // wait for a second
|
|
digitalWrite(RED, LOW); // turn the LED off by making the voltage LOW
|
|
delay(delay_ms); // wait for a second
|
|
digitalWrite(GREEN, HIGH);
|
|
delay(delay_ms);
|
|
digitalWrite(GREEN, LOW);
|
|
delay(delay_ms);
|
|
digitalWrite(BLUE, HIGH);
|
|
delay(delay_ms);
|
|
digitalWrite(BLUE, LOW);
|
|
delay(delay_ms);
|
|
}
|