Skip to content

Instantly share code, notes, and snippets.

@dmpayton
Created April 26, 2017 02:23
Show Gist options
  • Save dmpayton/5025de6e8d83439af58344ba3772bfbc to your computer and use it in GitHub Desktop.
Save dmpayton/5025de6e8d83439af58344ba3772bfbc to your computer and use it in GitHub Desktop.
Fresno.py arduino sketch
String incomingByte = ""; // for incoming serial data
bool blinking = false;
int blinkSpeed = 100;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
// the loop function runs over and over again forever
void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.readString();
if (incomingByte == "on") {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
blinking = false;
}
if (incomingByte == "off") {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
blinking = false;
}
if (incomingByte == "blink") {
blinking = true;
}
if (incomingByte == "faster") {
blinkSpeed -= 100;
}
if (incomingByte == "slower") {
blinkSpeed += 100;
}
}
if (blinking == true) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(blinkSpeed); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level)
delay(blinkSpeed); // wait for a second
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment