2013-12-29 20:12:21 +00:00
|
|
|
const unsigned int LED_PIN = 13;
|
|
|
|
const unsigned int BAUD_RATE = 9600;
|
|
|
|
|
2013-12-29 20:24:31 +00:00
|
|
|
void ledOn() {
|
2013-12-30 05:00:35 +00:00
|
|
|
digitalWrite(LED_PIN, HIGH);
|
|
|
|
Serial.println("LED on");
|
2013-12-29 20:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ledOff() {
|
2013-12-30 05:00:35 +00:00
|
|
|
digitalWrite(LED_PIN, LOW);
|
|
|
|
Serial.println("LED off");
|
2013-12-29 20:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ledBlink() {
|
2013-12-30 05:00:35 +00:00
|
|
|
Serial.println("BLINKY TIME");
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
ledOn();
|
|
|
|
delay(100);
|
|
|
|
ledOff();
|
|
|
|
delay(100);
|
|
|
|
}
|
2013-12-29 20:24:31 +00:00
|
|
|
}
|
|
|
|
|
2013-12-29 21:49:37 +00:00
|
|
|
void handleInput() {
|
2013-12-30 05:00:35 +00:00
|
|
|
int c = Serial.read();
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case '1':
|
|
|
|
ledOn();
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
ledOff();
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
ledBlink();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Serial.print("Unknown command: ");
|
|
|
|
Serial.println(c);
|
|
|
|
}
|
2013-12-29 21:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup() {
|
2013-12-30 05:00:35 +00:00
|
|
|
pinMode(LED_PIN, OUTPUT);
|
|
|
|
Serial.begin(BAUD_RATE);
|
2013-12-29 21:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2013-12-30 05:00:35 +00:00
|
|
|
if (Serial.available() <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-29 21:49:37 +00:00
|
|
|
|
2013-12-30 05:00:35 +00:00
|
|
|
handleInput();
|
2013-12-29 20:12:21 +00:00
|
|
|
}
|