summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2016-05-23 17:40:19 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2016-05-23 17:40:19 +0200
commitb12abf61ade782648e245dd258c590f9f64e394b (patch)
treee07a6d64e2e5420135f9b053729328986c4d4556
downloadadaledstripe-b12abf61ade782648e245dd258c590f9f64e394b.tar.gz
adaledstripe-b12abf61ade782648e245dd258c590f9f64e394b.zip
first commitHEADmaster
-rw-r--r--adaledstripe.ino56
1 files changed, 56 insertions, 0 deletions
diff --git a/adaledstripe.ino b/adaledstripe.ino
new file mode 100644
index 0000000..ef39c1e
--- /dev/null
+++ b/adaledstripe.ino
@@ -0,0 +1,56 @@
+//
+// Arduino serial-interface for controlling 1 analog led stripe. The serial interface is based on the
+// Adalight protocol. The protocol is as follows:
+// [prefix][led count][checksum][red, green, blue]*
+// prefix := 'Ada'
+// led count := number of leds - 1 (uint16_t big endian), unused in this case
+// checksum := led count high bit XOR led count low bit XOR 0x55 (uint8_t)
+// red, green, blue := channel intensity [0-255] (uint8_t)
+//
+
+/// The prefix for start sending led-data
+static const uint8_t prefix[] = {'A', 'd', 'a'};
+
+void setup()
+{
+ // Open the serial-connection
+ Serial.begin(115200);
+ // Send 'Ada' string to host
+ Serial.print("Ada\n");
+}
+
+void loop()
+{
+ int r, g, b;
+ // Wait for first byte of 'Ada'
+ for(int i = 0; i < sizeof(prefix); ++i)
+ {
+ while (!Serial.available());
+
+ // Check next byte in Magic Word
+ if(prefix[i] != Serial.read())
+ return;
+ }
+
+ // Wait for highByte, lowByte, Checksum to be available
+ while(Serial.available() < 3);
+ // Read high and low byte and the checksum
+ int highByte = Serial.read();
+ int lowByte = Serial.read();
+ int checksum = Serial.read();
+
+ if (checksum != (highByte ^ lowByte ^ 0x55))
+ {
+ // Checksum check failed
+ return;
+ }
+ // Wait for the next color spec to be available
+ while(Serial.available() < 3);
+ // Read the color spec
+ r = Serial.read();
+ g = Serial.read();
+ b = Serial.read();
+ analogWrite(3, r);
+ analogWrite(6, g);
+ analogWrite(5, b);
+}