diff options
author | daniel-Jones <daniel@danieljon.es> | 2017-12-08 17:38:21 +1030 |
---|---|---|
committer | daniel-Jones <daniel@danieljon.es> | 2017-12-08 17:38:21 +1030 |
commit | c39e7e667d51e368727807a9a2a6e482c6c63e52 (patch) | |
tree | 89cc92b74b4bc464a71eac06d862bef080b8f66a /arduino | |
parent | 5e02ba3073dfcac05d6fc2d0e26418b723f8d0fb (diff) | |
download | RGB-Controller-c39e7e667d51e368727807a9a2a6e482c6c63e52.tar.gz RGB-Controller-c39e7e667d51e368727807a9a2a6e482c6c63e52.zip |
added color up and down commands for incrementing/decrementing the colors individually remotely (over tcp for example)
Diffstat (limited to 'arduino')
-rw-r--r-- | arduino/rgb/rgb.ino | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/arduino/rgb/rgb.ino b/arduino/rgb/rgb.ino index bfadefa..5e2c289 100644 --- a/arduino/rgb/rgb.ino +++ b/arduino/rgb/rgb.ino @@ -1,9 +1,9 @@ #include <SPI.h> #include <Thread.h> -const int redPin = 2; -const int greenPin = 4; -const int bluePin = 3; +const int redPin = 4; +const int greenPin = 3; +const int bluePin = 2; int red = 0; int rf = 0; @@ -25,8 +25,6 @@ struct stat bool b_fade; } status; -void tests(); - void red_thread(); bool r_rev = false; @@ -64,19 +62,19 @@ void setup() void red_thread() { - if (red < rf) {red = rf;} - if (red > rt) {red = rf;} - if (red == rt) {r_rev = true;} - if (red == rf) {r_rev = false;} + if (red < rf) red = rf; + if (red > rt) red = rf; + if (red == rt) r_rev = true; + if (red == rf) r_rev = false; ((!r_rev) ? (red++, analogWrite(redPin, red)) : (red--, analogWrite(redPin, red))); } void green_thread() { - if (red < rf) {green = gf;} - if (green > gt) {green = gf;} - if (green == gt) {g_rev = true;} - if (green == gf) {g_rev = false;} + if (red < rf) green = gf; + if (green > gt) green = gf; + if (green == gt) g_rev = true; + if (green == gf) g_rev = false; ((!g_rev) ? (green++, analogWrite(greenPin, green)) : (green--, analogWrite(greenPin, green))); } @@ -132,6 +130,37 @@ void parse(String com) if (p1.equalsIgnoreCase("bf")) bf = p2.toInt(); if (p1.equalsIgnoreCase("bt")) bt = p2.toInt(); if (p1.equalsIgnoreCase("ping")) Serial.write("ping=pong\n"); + + /* color increment/decrement */ + if (p1.equalsIgnoreCase("ru") && red <= 255) + { + red++;analogWrite(redPin, red); + } + if (p1.equalsIgnoreCase("gu") && green <= 255) + { + green++;analogWrite(greenPin, green); + } + if (p1.equalsIgnoreCase("bu") && blue <= 255) + { + blue++;analogWrite(bluePin, blue); + } + + if (p1.equalsIgnoreCase("rd") && red > 0) + { + red--;analogWrite(redPin, red); + } + if (p1.equalsIgnoreCase("gd") && green > 0) + { + green--;analogWrite(greenPin, green); + } + if (p1.equalsIgnoreCase("bd") && blue > 0) + { + blue--;analogWrite(bluePin, blue); + } + + + + if (p1.equalsIgnoreCase("off")) { red = 0; |