summaryrefslogtreecommitdiff
path: root/arduino
diff options
context:
space:
mode:
authordaniel-Jones <daniel@danieljon.es>2017-02-13 16:06:14 +1030
committerdaniel-Jones <daniel@danieljon.es>2017-02-13 16:06:14 +1030
commit38d8f89f2f2b27fb25e0b4b9a34b45b76f6dc6f2 (patch)
tree0db331dc9834acd3aed82033012d840946d02dfd /arduino
parentf7bbb4f3d4325df390ce54cbb46c99a964a5a508 (diff)
downloadRGB-Controller-38d8f89f2f2b27fb25e0b4b9a34b45b76f6dc6f2.tar.gz
RGB-Controller-38d8f89f2f2b27fb25e0b4b9a34b45b76f6dc6f2.zip
added fade ability to Arduino sketch, using psuedo threading. Rework of serial communication also started, the Qt interface is currently under development to support fading.
Diffstat (limited to 'arduino')
-rw-r--r--arduino/rgb/.plan.txt.swpbin0 -> 12288 bytes
-rw-r--r--arduino/rgb/.rgb.ino.swpbin0 -> 12288 bytes
-rw-r--r--arduino/rgb/plan.txt14
-rw-r--r--arduino/rgb/rgb.ino130
-rw-r--r--arduino/rgb/rgb.inoold44
-rw-r--r--arduino/rgb/test.in103
6 files changed, 258 insertions, 33 deletions
diff --git a/arduino/rgb/.plan.txt.swp b/arduino/rgb/.plan.txt.swp
new file mode 100644
index 0000000..e9905dc
--- /dev/null
+++ b/arduino/rgb/.plan.txt.swp
Binary files differ
diff --git a/arduino/rgb/.rgb.ino.swp b/arduino/rgb/.rgb.ino.swp
new file mode 100644
index 0000000..d5c3851
--- /dev/null
+++ b/arduino/rgb/.rgb.ino.swp
Binary files differ
diff --git a/arduino/rgb/plan.txt b/arduino/rgb/plan.txt
new file mode 100644
index 0000000..d5bda5d
--- /dev/null
+++ b/arduino/rgb/plan.txt
@@ -0,0 +1,14 @@
+
+
+loop {
+
+ special function thread
+ serial handle
+
+}
+
+special function thread {
+
+
+
+}
diff --git a/arduino/rgb/rgb.ino b/arduino/rgb/rgb.ino
index 702fbe1..7d61ceb 100644
--- a/arduino/rgb/rgb.ino
+++ b/arduino/rgb/rgb.ino
@@ -1,4 +1,6 @@
-int incomingByte = 0; // for incoming serial data
+#include <SPI.h>
+#include <Thread.h>
+
const int redPin = 2;
const int greenPin = 4;
const int bluePin = 3;
@@ -7,38 +9,100 @@ int red;
int green;
int blue;
-String inData;
-void setup() {
- Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
- red = 0;
- green = 0;
- blue = 0;
- pinMode(redPin, OUTPUT);
- pinMode(greenPin, OUTPUT);
- pinMode(bluePin, OUTPUT);
+void red_thread();
+bool r_rev = false;
+
+void green_thread();
+bool g_rev = false;
+
+void blue_thread();
+bool b_rev = false;
+
+Thread r_fade = Thread();
+Thread g_fade = Thread();
+Thread b_fade = Thread();
+
+void setup()
+{
+ Serial.begin(9600);
+ pinMode(redPin, OUTPUT);
+ 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);
+
+ g_fade.enabled = false;
+ g_fade.onRun(green_thread);
+ g_fade.setInterval(10);
+
+ b_fade.enabled = false;
+ b_fade.onRun(blue_thread);
+ b_fade.setInterval(10);
+
}
-void loop() {
-
- // send data only when you receive data:
- if (Serial.available() > 0) {
- char recieved = Serial.read();
- inData += recieved;
-
- // Process message when new line character is recieved
- if (recieved == '\n')
- {
- Serial.print("string: ");
- Serial.print(inData);
- String first = Serial.readStringUntil(',');
- Serial.read(); //next character is comma, so skip it using this
- String second = Serial.readStringUntil(',');
- Serial.read();
- String third = Serial.readStringUntil('\0');
- Serial.print(first + "\n");
- Serial.print(second + "\n");
- Serial.print(third + "\n");
- inData = ""; // Clear recieved buffer
- }
- }
+void red_thread()
+{
+ if (red == 255)
+ r_rev = true;
+ if (red == 0)
+ r_rev = false;
+ if (!r_rev)
+ red++;analogWrite(redPin, red);
+ if (r_rev)
+ red--;analogWrite(redPin, red);
+}
+
+void green_thread()
+{
+ if (green == 255)
+ g_rev = true;
+ if (green == 0)
+ g_rev = false;
+ if (!g_rev)
+ green++;analogWrite(greenPin, green);
+ if (g_rev)
+ green--;analogWrite(greenPin, green);
+}
+
+
+void blue_thread()
+{
+ if (blue == 255)
+ b_rev = true;
+ if (blue == 0)
+ b_rev = false;
+ if (!b_rev)
+ blue++;analogWrite(bluePin, blue);
+ if (b_rev)
+ blue--;analogWrite(bluePin, blue);
+}
+
+
+void loop()
+{
+ if (r_fade.shouldRun())
+ r_fade.run();
+ if (g_fade.shouldRun())
+ g_fade.run();
+ if (b_fade.shouldRun())
+ b_fade.run();
+
+ /* read serial data */
+ while (Serial.available() > 1)
+ {
+
+ red = Serial.parseInt();
+ green = Serial.parseInt();
+ blue = Serial.parseInt();
+ analogWrite(redPin, red);
+ analogWrite(greenPin, green);
+ analogWrite(bluePin, blue);
+ }
}
diff --git a/arduino/rgb/rgb.inoold b/arduino/rgb/rgb.inoold
new file mode 100644
index 0000000..702fbe1
--- /dev/null
+++ b/arduino/rgb/rgb.inoold
@@ -0,0 +1,44 @@
+int incomingByte = 0; // for incoming serial data
+const int redPin = 2;
+const int greenPin = 4;
+const int bluePin = 3;
+
+int red;
+int green;
+int blue;
+
+String inData;
+void setup() {
+ Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
+ red = 0;
+ green = 0;
+ blue = 0;
+ pinMode(redPin, OUTPUT);
+ pinMode(greenPin, OUTPUT);
+ pinMode(bluePin, OUTPUT);
+}
+
+void loop() {
+
+ // send data only when you receive data:
+ if (Serial.available() > 0) {
+ char recieved = Serial.read();
+ inData += recieved;
+
+ // Process message when new line character is recieved
+ if (recieved == '\n')
+ {
+ Serial.print("string: ");
+ Serial.print(inData);
+ String first = Serial.readStringUntil(',');
+ Serial.read(); //next character is comma, so skip it using this
+ String second = Serial.readStringUntil(',');
+ Serial.read();
+ String third = Serial.readStringUntil('\0');
+ Serial.print(first + "\n");
+ Serial.print(second + "\n");
+ Serial.print(third + "\n");
+ inData = ""; // Clear recieved buffer
+ }
+ }
+}
diff --git a/arduino/rgb/test.in b/arduino/rgb/test.in
new file mode 100644
index 0000000..dd28395
--- /dev/null
+++ b/arduino/rgb/test.in
@@ -0,0 +1,103 @@
+#include <SPI.h>
+#include <Adafruit_GFX.h>
+#include <Adafruit_SSD1306.h>
+
+const int PRED = 2;
+const int PGREEN = 4;
+const int PBLUE = 3;
+
+#define OLED_RESET 4
+
+#define WIDTH 128
+#define HEIGHT 64
+
+Adafruit_SSD1306 display(OLED_RESET);
+
+/* storage */
+int red;
+int green;
+int blue;
+
+class menuitem
+{
+ public:
+ String name;
+ String desc;
+};
+
+menuitem items[6];
+
+void setup()
+{
+ Serial.begin(9600);
+ pinMode(PRED, OUTPUT);
+ pinMode(PGREEN, OUTPUT);
+ pinMode(PBLUE, OUTPUT);
+
+ /* set all values to 0 */
+ red = 0;
+ green = 0;
+ blue = 0;
+// setupmenu();
+ //display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
+ display.clearDisplay();
+}
+
+void loop()
+{
+ rgb();
+ display.clearDisplay();
+ //menu();
+ oledwrite(0,0,3,"testtt");
+ display.display();
+
+}
+
+void setupmenu()
+{
+ for (int x = 0; x < sizeof(items); x++)
+ {
+ items[x] = menuitem();
+ }
+ items[0].name = "test 1";
+ items[0].desc = "first test";
+}
+
+void menu()
+{
+ oledwrite(0, 0, 2, items[0].name);
+ oledwrite(60, 0, 2, items[0].desc);
+}
+
+void oledwrite(int x, int y, int size, String text)
+{
+ display.setTextSize(size);
+ display.setTextColor(WHITE);
+ display.setCursor(x, y);
+ display.println(text);
+}
+
+void oledpixel(int x, int y)
+{
+ display.drawPixel(x, y, 1);
+}
+
+void oledline(int x1, int y1, int x2, int y2)
+{
+ display.drawLine(x1, y1, x2, y2, WHITE);
+}
+
+void rgb()
+{
+ /* read serial data */
+ while (Serial.available() > 1)
+ {
+ red = Serial.parseInt();
+ green = Serial.parseInt();
+ blue = Serial.parseInt();
+ analogWrite(PRED, red);
+ analogWrite(PGREEN, green);
+ analogWrite(PBLUE, blue);
+ }
+
+}