diff --git a/arduino/Makefile b/arduino/Makefile index 6ad64b8..5f9669a 100644 --- a/arduino/Makefile +++ b/arduino/Makefile @@ -5,6 +5,10 @@ EVERYTHING := \ .PHONY: all all: $(EVERYTHING) +.PHONY: all +style: + astyle -r '*.ino' -n + arduino.mk: curl -L -o $@ -s http://ed.am/dev/make/arduino-mk/arduino.mk diff --git a/arduino/misc/ConnecticutHalftime/ConnecticutHalftime.ino b/arduino/misc/ConnecticutHalftime/ConnecticutHalftime.ino index 6035e74..4882f33 100644 --- a/arduino/misc/ConnecticutHalftime/ConnecticutHalftime.ino +++ b/arduino/misc/ConnecticutHalftime/ConnecticutHalftime.ino @@ -32,7 +32,7 @@ void playNote(int note) { void playMeasure(int measure[]) { - for (int i = 0;;i++) { + for (int i = 0;; i++) { int note = measure[i]; if (note == 0) { return; diff --git a/arduino/msaqsg/ch01/HelloWorld/HelloWorld.ino b/arduino/msaqsg/ch01/HelloWorld/HelloWorld.ino index ce2d2f6..f8927e8 100644 --- a/arduino/msaqsg/ch01/HelloWorld/HelloWorld.ino +++ b/arduino/msaqsg/ch01/HelloWorld/HelloWorld.ino @@ -4,24 +4,24 @@ const unsigned int FLASH_DURATION = 100; void flash(int n) { - for (int i = 0; i < n; i++) { - digitalWrite(LED_PIN, HIGH); - delay(FLASH_DURATION); - digitalWrite(LED_PIN, LOW); - delay(FLASH_DURATION); - } + for (int i = 0; i < n; i++) { + digitalWrite(LED_PIN, HIGH); + delay(FLASH_DURATION); + digitalWrite(LED_PIN, LOW); + delay(FLASH_DURATION); + } } void setup() { - pinMode(LED_PIN, OUTPUT); + pinMode(LED_PIN, OUTPUT); } void loop() { - for (int i = 1; i < 4; i++) { - flash(i); + for (int i = 1; i < 4; i++) { + flash(i); + delay(PAUSE); + } delay(PAUSE); - } - delay(PAUSE); } diff --git a/arduino/msaqsg/ch02/LEDSwitch/LEDSwitch.ino b/arduino/msaqsg/ch02/LEDSwitch/LEDSwitch.ino index e9a4b4b..670308e 100644 --- a/arduino/msaqsg/ch02/LEDSwitch/LEDSwitch.ino +++ b/arduino/msaqsg/ch02/LEDSwitch/LEDSwitch.ino @@ -2,53 +2,53 @@ const unsigned int LED_PIN = 13; const unsigned int BAUD_RATE = 9600; void ledOn() { - digitalWrite(LED_PIN, HIGH); - Serial.println("LED on"); + digitalWrite(LED_PIN, HIGH); + Serial.println("LED on"); } void ledOff() { - digitalWrite(LED_PIN, LOW); - Serial.println("LED off"); + 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); - } + 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); - } + 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); + pinMode(LED_PIN, OUTPUT); + Serial.begin(BAUD_RATE); } void loop() { - if (Serial.available() <= 0) { - return; - } + if (Serial.available() <= 0) { + return; + } - handleInput(); + handleInput(); } diff --git a/arduino/msaqsg/ch03/DebounceButton/DebounceButton.ino b/arduino/msaqsg/ch03/DebounceButton/DebounceButton.ino index a5b1522..b2a970d 100644 --- a/arduino/msaqsg/ch03/DebounceButton/DebounceButton.ino +++ b/arduino/msaqsg/ch03/DebounceButton/DebounceButton.ino @@ -13,7 +13,7 @@ void loop() { const int CURRENT_BUTTON_STATE = digitalRead(BUTTON_PIN); if (CURRENT_BUTTON_STATE != oldButtonState && - CURRENT_BUTTON_STATE == HIGH) { + CURRENT_BUTTON_STATE == HIGH) { if (ledState == LOW) { ledState = HIGH; } else { diff --git a/arduino/msaqsg/ch03/MoreReliableSwitch/MoreReliableSwitch.ino b/arduino/msaqsg/ch03/MoreReliableSwitch/MoreReliableSwitch.ino index 2b67b72..2cbf8e5 100644 --- a/arduino/msaqsg/ch03/MoreReliableSwitch/MoreReliableSwitch.ino +++ b/arduino/msaqsg/ch03/MoreReliableSwitch/MoreReliableSwitch.ino @@ -13,7 +13,7 @@ void loop() { const int CURRENT_BUTTON_STATE = digitalRead(BUTTON_PIN); if (CURRENT_BUTTON_STATE != oldButtonState && - CURRENT_BUTTON_STATE == HIGH) { + CURRENT_BUTTON_STATE == HIGH) { if (ledState == LOW) { ledState = HIGH; } else {