Last active
January 4, 2016 11:37
-
-
Save lennart/207ad2e1ca6ff8cb6e3a to your computer and use it in GitHub Desktop.
Lo-Fi Arduino Tidal binding, makes lights go on by color name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Tidal <-> Arduino | |
send rhythmic patterns to custom hardware | |
assumes three leds connected to Arduino on Digital Pins: | |
13 red | |
12 yellow | |
11 green | |
*/ | |
#include "Arduino.h" | |
#ifndef TIDAL_SERIAL_SPEED | |
#define TIDAL_SERIAL_SPEED 115200 | |
#endif | |
String inputString = ""; // a string to hold incoming data | |
boolean stringComplete = false; // whether the string is complete | |
int redled = 13; | |
int yellowled = 12; | |
int greenled = 11; | |
unsigned long redtimeout; | |
unsigned long yellowtimeout; | |
unsigned long greentimeout; | |
bool lighting = false; | |
void setup() { | |
// initialize serial: | |
Serial.begin(TIDAL_SERIAL_SPEED); | |
Serial.println("Tidal Blink example"); | |
// reserve 200 bytes for the inputString: | |
inputString.reserve(200); | |
redtimeout = millis(); | |
yellowtimeout = redtimeout; | |
greentimeout = yellowtimeout; | |
pinMode(redled, OUTPUT); | |
pinMode(yellowled, OUTPUT); | |
pinMode(greenled, OUTPUT); | |
digitalWrite(redled, LOW); | |
digitalWrite(yellowled, LOW); | |
digitalWrite(greenled, LOW); | |
} | |
/* | |
SerialEvent occurs whenever a new data comes in the | |
hardware serial RX. This routine is run between each | |
time loop() runs, so using delay inside loop can delay | |
response. Multiple bytes of data may be available. | |
*/ | |
void serialEvent() { | |
while (Serial.available()) { | |
// get the new byte: | |
char inChar = (char)Serial.read(); | |
// add it to the inputString: | |
inputString += inChar; | |
// if the incoming character is a newline, set a flag | |
// so the main loop can do something about it: | |
if (inChar == '\n') { | |
stringComplete = true; | |
} | |
} | |
} | |
void loop() { | |
serialEvent(); //call the function | |
if (stringComplete) { | |
if (inputString.startsWith("red")) { | |
redtimeout = millis() + 250; | |
} | |
if (inputString.startsWith("yellow")) { | |
yellowtimeout = millis() + 250; | |
} | |
if (inputString.startsWith("green")) { | |
greentimeout = millis() + 250; | |
} | |
// clear the string: | |
inputString = ""; | |
stringComplete = false; | |
} | |
if ((millis() - redtimeout) > 0) digitalWrite(redled, LOW); | |
else digitalWrite(redled, HIGH); | |
if ((millis() - yellowtimeout) > 0) digitalWrite(yellowled, LOW); | |
else digitalWrite(yellowled, HIGH); | |
if ((millis() - greentimeout) > 0) digitalWrite(greenled, LOW); | |
else digitalWrite(greenled, HIGH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment