Created
November 9, 2017 15:35
-
-
Save honnet/a7b2ff3381e082afa71ad7cd949baa75 to your computer and use it in GitHub Desktop.
blink X times for Y ms with X and Y sent over serial
This file contains 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
int led_pin = LED_BUILTIN; | |
void setup() { | |
pinMode(led_pin, OUTPUT); | |
digitalWrite(led_pin, LOW); | |
Serial.begin(115200); | |
Serial.println("hello!"); | |
} | |
// parse messages such as "3;100" (3 blinks of 100ms)... | |
void loop() { | |
if (Serial.available() > 0) { // check if we received something | |
Serial.println(Serial.read()); | |
int X = Serial.parseInt(); // number of blinks | |
Serial.println(X); | |
int Y = Serial.parseInt(); // duration of blinks | |
Serial.println(Y); | |
for (int i = 0; i < X; i++) { // loop Y times | |
digitalWrite(led_pin, HIGH); | |
delay(Y); | |
digitalWrite(led_pin, LOW); | |
delay(Y); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment