diff options
author | daniel-Jones <daniel@danieljon.es> | 2017-06-04 16:26:56 +0930 |
---|---|---|
committer | daniel-Jones <daniel@danieljon.es> | 2017-06-04 16:26:56 +0930 |
commit | f66536d84b38aa0eb46e928fdaf13d7da790b2ee (patch) | |
tree | ba2624354136f3f0db3ec929d1eea15635527ba1 /arduino | |
parent | 2ce2f6376152402c3fc0d750720770b963a7d3cf (diff) | |
download | RGB-Controller-f66536d84b38aa0eb46e928fdaf13d7da790b2ee.tar.gz RGB-Controller-f66536d84b38aa0eb46e928fdaf13d7da790b2ee.zip |
added HTML/JS/PHP pages/scripts to allow RGB changes over a web page. Integrated a server into the application to allow incoming connections and receive commands
Diffstat (limited to 'arduino')
-rw-r--r-- | arduino/rgb/rgb.ino | 251 | ||||
-rw-r--r-- | arduino/rgb/tags | 6 |
2 files changed, 180 insertions, 77 deletions
diff --git a/arduino/rgb/rgb.ino b/arduino/rgb/rgb.ino index aa35aa0..52e9519 100644 --- a/arduino/rgb/rgb.ino +++ b/arduino/rgb/rgb.ino @@ -1,5 +1,9 @@ #include <SPI.h> #include <Thread.h> +#include <Adafruit_GFX.h> +#include <Adafruit_SSD1306.h> +#define OLED_RESET 4 +Adafruit_SSD1306 display(OLED_RESET); const int redPin = 2; const int greenPin = 4; @@ -15,6 +19,8 @@ int blue = 0; int bf = 0; int bt = 255; +void tests(); + void red_thread(); bool r_rev = false; @@ -24,14 +30,65 @@ bool g_rev = false; void blue_thread(); bool b_rev = false; +void draw_square(struct square *sq); + Thread r_fade = Thread(); Thread g_fade = Thread(); Thread b_fade = Thread(); + +struct square { + int x1; // top left + int x2; // top right + int x3; // bottom left + int x4; //bottom right + int y1; //top left + int y2; // top right + int y3; // bottom left + int y4; // bottom right +}; + + +struct square sq1; + +struct square sq2; + + + void parse(String com); +void OledWrite(int x, int y, int size, String text) { // this function will write to our oled + display.setTextSize(size); // set the font size + display.setTextColor(WHITE); // set the font color + display.setCursor(x, y); // set the cursor position + display.println(text); // add our text to the oled buffer + display.display(); +} + void setup() { + sq1.x1 = 0; + sq1.x2 = 30; + sq1.x3 = 0; + sq1.x4 = 30; + sq1.y1 = 0; + sq1.y2 = 0; + sq1.y3 = 30; + sq1.y4 = 30; + + + sq2.x1 = 60; + sq2.x2 = 90; + sq2.x3 = 60; + sq2.x4 = 90; + sq2.y1 = 0; + sq2.y2 = 0; + sq2.y3 = 30; + sq2.y4 = 30; + + + display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // lets begin our oled display/connection + display.clearDisplay(); // clear oled display from anything left over from last session Serial.begin(9600); pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); @@ -42,12 +99,12 @@ void setup() r_fade.setInterval(10); g_fade.enabled = false; - g_fade.onRun(green_thread); - g_fade.setInterval(10); + g_fade.onRun(green_thread); + g_fade.setInterval(10); b_fade.enabled = false; - b_fade.onRun(blue_thread); - b_fade.setInterval(10); + b_fade.onRun(blue_thread); + b_fade.setInterval(10); } @@ -57,47 +114,47 @@ void red_thread() red = rf; if (red > rt) red = rf; - if (red == rt) - r_rev = true; - if (red == rf) - r_rev = false; - if (!r_rev) - red++;analogWrite(redPin, red); - if (r_rev) - red--;analogWrite(redPin, red); + if (red == rt) + r_rev = true; + if (red == rf) + r_rev = false; + if (!r_rev) + red++;analogWrite(redPin, red); + if (r_rev) + 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 (!g_rev) - green++;analogWrite(greenPin, green); - if (g_rev) - green--;analogWrite(greenPin, green); + green = gf; + if (green > gt) + green = gf; + if (green == gt) + g_rev = true; + if (green == gf) + g_rev = false; + if (!g_rev) + green++;analogWrite(greenPin, green); + if (g_rev) + green--;analogWrite(greenPin, green); } void blue_thread() { if (blue < bf) - red = bf; - if (blue > bt) - blue = bf; - if (blue == bt) - b_rev = true; - if (blue == bf) - b_rev = false; - if (!b_rev) - blue++;analogWrite(bluePin, blue); - if (b_rev) - blue--;analogWrite(bluePin, blue); + red = bf; + if (blue > bt) + blue = bf; + if (blue == bt) + b_rev = true; + if (blue == bf) + b_rev = false; + if (!b_rev) + blue++;analogWrite(bluePin, blue); + if (b_rev) + blue--;analogWrite(bluePin, blue); } void parse(String com) @@ -113,52 +170,52 @@ void parse(String com) analogWrite(redPin, red); } if (p1.equalsIgnoreCase("green")) - { - green = p2.toInt(); + { + green = p2.toInt(); analogWrite(greenPin, green); - } + } if (p1.equalsIgnoreCase("blue")) - { - blue = p2.toInt(); + { + blue = p2.toInt(); analogWrite(bluePin, blue); - } + } if (p1.equalsIgnoreCase("redfade")) - { + { if (r_fade.enabled) - r_fade.enabled = false; + 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 (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 (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()); @@ -168,15 +225,32 @@ void parse(String com) if (p1.equalsIgnoreCase("rt")) rt = p2.toInt(); if (p1.equalsIgnoreCase("gf")) - gf = p2.toInt(); - if (p1.equalsIgnoreCase("gt")) - gt = p2.toInt(); + gf = p2.toInt(); + if (p1.equalsIgnoreCase("gt")) + gt = p2.toInt(); if (p1.equalsIgnoreCase("bf")) - bf = p2.toInt(); - if (p1.equalsIgnoreCase("bt")) - bt = p2.toInt(); + bf = p2.toInt(); + if (p1.equalsIgnoreCase("bt")) + bt = p2.toInt(); if (p1.equalsIgnoreCase("ping")) Serial.write("ping=pong\n"); + if (p1.equalsIgnoreCase("write")) + { + display.clearDisplay(); + OledWrite(0, 0, 3, p2); + } + if (p1.equalsIgnoreCase("off")) + { + red = 0; + green = 0; + blue = 0; + r_fade.enabled = false; + g_fade.enabled = false; + b_fade.enabled = false; + analogWrite(redPin, red); + analogWrite(greenPin, green); + analogWrite(bluePin, blue); + } } String line; @@ -186,9 +260,9 @@ void loop() if (r_fade.shouldRun()) r_fade.run(); if (g_fade.shouldRun()) - g_fade.run(); + g_fade.run(); if (b_fade.shouldRun()) - b_fade.run(); + b_fade.run(); /* read serial data */ while (Serial.available()) @@ -204,4 +278,27 @@ void loop() line += c; } } + tests(); +} + +void tests() +{ + display.clearDisplay(); + + draw_square(&sq1); + draw_square(&sq2); + + display.display(); +} + +void draw_square(struct square *sq) +{ + /* top left -> top right */ + display.drawLine(sq->x2, sq->y1, sq->x1, sq->y2, WHITE); + /* top right -> bottom right */ + display.drawLine(sq->x2, sq->y2, sq->x4, sq->y4, WHITE); + /* bottom right -> bottom left */ + display.drawLine(sq->x4, sq->y4, sq->x3, sq->y3, WHITE); + /* bottom left -> top left */ + display.drawLine(sq->x3, sq->y3, sq->x1, sq->y1, WHITE); } diff --git a/arduino/rgb/tags b/arduino/rgb/tags new file mode 100644 index 0000000..d01d39b --- /dev/null +++ b/arduino/rgb/tags @@ -0,0 +1,6 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ +!_TAG_PROGRAM_NAME Exuberant Ctags // +!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ +!_TAG_PROGRAM_VERSION 5.8 // |