Created
January 1, 2016 00:58
-
-
Save arselzer/26e3b3fc378810c3b30a to your computer and use it in GitHub Desktop.
This file contains 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
const int R8 = 7; // top left | |
const int R4 = 6; // top right | |
const int LEDR = 8; | |
const int LEDG = 10; | |
const int LEDB = 9; | |
void setRGB(int r, int g, int b) { | |
digitalWrite(LEDR, r); | |
digitalWrite(LEDG, g); | |
digitalWrite(LEDB, b); | |
} | |
void setup() { | |
pinMode(5, OUTPUT); // always on | |
digitalWrite(5, HIGH); | |
pinMode(R8, OUTPUT); | |
digitalWrite(R8, HIGH); | |
pinMode(R4, OUTPUT); | |
digitalWrite(R4, HIGH); | |
pinMode(LEDR, OUTPUT); | |
pinMode(LEDG, OUTPUT); | |
pinMode(LEDB, OUTPUT); | |
setRGB(0, 1, 0); | |
Serial.begin(9600); | |
Serial.write("start"); | |
} | |
void loop() { | |
while (Serial.available() > 0) { | |
int v = Serial.parseInt(); | |
if (Serial.read() == '\n') { | |
Serial.print("Ok "); | |
Serial.println(v); | |
// anti self-destruct | |
if (v < 5000) { | |
// red light | |
setRGB(1, 0, 0); | |
// relay on | |
digitalWrite(R4, LOW); | |
delay(v); | |
// relay off | |
digitalWrite(R4, HIGH); | |
// green light | |
setRGB(0, 1, 0); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment