summaryrefslogtreecommitdiff
path: root/arduino
diff options
context:
space:
mode:
authordaniel-Jones <daniel@danieljon.es>2017-02-15 12:17:06 +1030
committerdaniel-Jones <daniel@danieljon.es>2017-02-15 12:17:06 +1030
commit12bddeda97b5d428f4ef9006180051c14b01aecc (patch)
treec70ac463f9f244f19095f3e7268894f3da04c6fa /arduino
parent38d8f89f2f2b27fb25e0b4b9a34b45b76f6dc6f2 (diff)
downloadRGB-Controller-12bddeda97b5d428f4ef9006180051c14b01aecc.tar.gz
RGB-Controller-12bddeda97b5d428f4ef9006180051c14b01aecc.zip
Fade with individual speed control now works, can fade each color at its own speed. Serial communication revamped to allow extra commands in both the front and backend.
Diffstat (limited to 'arduino')
-rw-r--r--arduino/rgb/.plan.txt.swpbin12288 -> 0 bytes
-rw-r--r--arduino/rgb/rgb.ino128
2 files changed, 108 insertions, 20 deletions
diff --git a/arduino/rgb/.plan.txt.swp b/arduino/rgb/.plan.txt.swp
deleted file mode 100644
index e9905dc..0000000
--- a/arduino/rgb/.plan.txt.swp
+++ /dev/null
Binary files differ
diff --git a/arduino/rgb/rgb.ino b/arduino/rgb/rgb.ino
index 7d61ceb..3c29aee 100644
--- a/arduino/rgb/rgb.ino
+++ b/arduino/rgb/rgb.ino
@@ -5,9 +5,15 @@ const int redPin = 2;
const int greenPin = 4;
const int bluePin = 3;
-int red;
-int green;
-int blue;
+int red = 0;
+int rf = 0;
+int rt = 255;
+int green = 0;
+int gf = 0;
+int gt = 255;
+int blue = 0;
+int bf = 0;
+int bt = 255;
void red_thread();
bool r_rev = false;
@@ -22,6 +28,8 @@ Thread r_fade = Thread();
Thread g_fade = Thread();
Thread b_fade = Thread();
+void parse(String com);
+
void setup()
{
Serial.begin(9600);
@@ -29,10 +37,6 @@ void setup()
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
- /* set all values to 0 */
- red = 0;
- green = 0;
- blue = 0;
r_fade.enabled = false;
r_fade.onRun(red_thread);
r_fade.setInterval(10);
@@ -49,9 +53,9 @@ void setup()
void red_thread()
{
- if (red == 255)
+ if (red == rt)
r_rev = true;
- if (red == 0)
+ if (red == rf)
r_rev = false;
if (!r_rev)
red++;analogWrite(redPin, red);
@@ -61,9 +65,9 @@ void red_thread()
void green_thread()
{
- if (green == 255)
+ if (green == gt)
g_rev = true;
- if (green == 0)
+ if (green == gf)
g_rev = false;
if (!g_rev)
green++;analogWrite(greenPin, green);
@@ -74,9 +78,9 @@ void green_thread()
void blue_thread()
{
- if (blue == 255)
+ if (blue == bt)
b_rev = true;
- if (blue == 0)
+ if (blue == bf)
b_rev = false;
if (!b_rev)
blue++;analogWrite(bluePin, blue);
@@ -84,6 +88,86 @@ void blue_thread()
blue--;analogWrite(bluePin, blue);
}
+void parse(String com)
+{
+ String p1;
+ String p2;
+
+ p1 = com.substring(0, com.indexOf("="));
+ p2 = com.substring(com.indexOf("=") + 1);
+
+ if (p1.equalsIgnoreCase("red"))
+ {
+ red = p2.toInt();
+ analogWrite(redPin, red);
+ }
+ if (p1.equalsIgnoreCase("green"))
+ {
+ green = p2.toInt();
+ analogWrite(greenPin, green);
+ }
+ if (p1.equalsIgnoreCase("blue"))
+ {
+ blue = p2.toInt();
+ analogWrite(bluePin, blue);
+ }
+ if (p1.equalsIgnoreCase("redfade"))
+ {
+ if (r_fade.enabled)
+ r_fade.enabled = false;
+ else if (!r_fade.enabled)
+ r_fade.enabled = true;
+ }
+ if (p1.equalsIgnoreCase("greenfade"))
+ {
+ if (g_fade.enabled)
+ g_fade.enabled = false;
+ else if (!g_fade.enabled)
+ g_fade.enabled = true;
+ }
+ if (p1.equalsIgnoreCase("bluefade"))
+ {
+ if (b_fade.enabled)
+ b_fade.enabled = false;
+ else if (!b_fade.enabled)
+ b_fade.enabled = true;
+ }
+ if (p1.equalsIgnoreCase("rspeed"))
+ {
+ r_fade.setInterval(p2.toInt());
+ }
+ if (p1.equalsIgnoreCase("gspeed"))
+ {
+ g_fade.setInterval(p2.toInt());
+ }
+
+ if (p1.equalsIgnoreCase("bspeed"))
+ {
+ b_fade.setInterval(p2.toInt());
+ }
+
+ if (p1.equalsIgnoreCase("speed"))
+ {
+ r_fade.setInterval(p2.toInt());
+ g_fade.setInterval(p2.toInt());
+ b_fade.setInterval(p2.toInt());
+ }
+ if (p1.equalsIgnoreCase("rf"))
+ rf = p2.toInt();
+ if (p1.equalsIgnoreCase("rt"))
+ rt = p2.toInt();
+ if (p1.equalsIgnoreCase("gf"))
+ gf = p2.toInt();
+ if (p1.equalsIgnoreCase("gt"))
+ gt = p2.toInt();
+ if (p1.equalsIgnoreCase("bf"))
+ bf = p2.toInt();
+ if (p1.equalsIgnoreCase("bt"))
+ bt = p2.toInt();
+
+}
+
+String line;
void loop()
{
@@ -95,14 +179,18 @@ void loop()
b_fade.run();
/* read serial data */
- while (Serial.available() > 1)
+ while (Serial.available())
{
+ char c = Serial.read();
+ if (c == '\n')
+ {
+ parse(line);
+ line = "";
+ }
+ else
+ {
+ line += c;
+ }
- red = Serial.parseInt();
- green = Serial.parseInt();
- blue = Serial.parseInt();
- analogWrite(redPin, red);
- analogWrite(greenPin, green);
- analogWrite(bluePin, blue);
}
}