Archiving a bunch of old stuff
This commit is contained in:
54
oldstuff/arduino/msaqsg/ch02/LEDSwitch/LEDSwitch.ino
Normal file
54
oldstuff/arduino/msaqsg/ch02/LEDSwitch/LEDSwitch.ino
Normal file
@@ -0,0 +1,54 @@
|
||||
const unsigned int LED_PIN = 13;
|
||||
const unsigned int BAUD_RATE = 9600;
|
||||
|
||||
void ledOn() {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
Serial.println("LED on");
|
||||
}
|
||||
|
||||
void ledOff() {
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
Serial.println("LED off");
|
||||
}
|
||||
|
||||
void ledBlink() {
|
||||
Serial.println("BLINKY TIME");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ledOn();
|
||||
delay(100);
|
||||
ledOff();
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
void handleInput() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
Serial.begin(BAUD_RATE);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
handleInput();
|
||||
}
|
1
oldstuff/arduino/msaqsg/ch02/LEDSwitch/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch02/LEDSwitch/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
Reference in New Issue
Block a user