Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void loop()
- {
- int blink = 0 /* if you initialize incomingByte somewhere else, you should probably move this one there too */
- while (1) /* loop forever */
- {
- if (Serial.available()) /* read and process commands on the serial line */
- {
- incomingByte = Serial.read();
- switch (incomingByte)
- {
- case '1' : /* enable blinking */
- {
- blink = 1;
- break;
- }
- case '2' : /* disable blinking */
- {
- blink = 0;
- break;
- }
- }
- }
- if (blink) /* when enabled, blink leds */
- {
- digitalWrite(led2, HIGH);
- delay(300);
- digitalWrite(led2, LOW);
- digitalWrite(led1, HIGH);
- delay(300)
- digitalWrite(led1, LOW);
- }
- }
- }
- less expandable option but possibly working:
- void loop()
- {
- if (Serial.available()) /* read command on the serial line */
- {
- incomingByte = Serial.read();
- }
- /* if there is nothing on the serial line, then the previous value is used, so if you pressed 1 then it is
- still 1, anything else than a 1 will disable the show until you press 1 again */
- if (incomingByte == '1') /* when enabled, blink leds */
- {
- digitalWrite(led2, HIGH);
- delay(300);
- digitalWrite(led2, LOW);
- digitalWrite(led1, HIGH);
- delay(300)
- digitalWrite(led1, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement