From 528fd00ecf92523096503b3cb8d97e99a6a09124 Mon Sep 17 00:00:00 2001 From: emuDrache Date: Sun, 9 Apr 2017 16:24:05 +0200 Subject: [PATCH 1/7] eCog106 demo (Button Only) eCog106 demo (Button Only) --- .../eCog106-Button-and-LED.ino | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino diff --git a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino new file mode 100644 index 0000000..56f6675 --- /dev/null +++ b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino @@ -0,0 +1,85 @@ +/************************************************************** + * Use this sketch to test the Button and LED eCog + * + * eCogs Used: + * eCog106 - Button & LED - Connect to eCog D + * + * Libraries required (Install with Library Manager): + * GadgetBox + * + * GadgetBox Motherboards supported: + * Arduino Mini Pro + * + * + * Demo by emuDrache + * + **************************************************************/ + + #include + + #define eCogButton1 DC0 + #define eCogButton2 DC1 // Analog Only Pin! (A6/GB9) + #define eCogButton3 DC2 // Analog Only Pin! (A7/GB10) + #define eCogButton4 DC3 + + #define ArduinoLED 13 // Arduino soldered to Arduino Mini Pro + + /* + * + * Handles reading from the digital/analog pin mishmash, + * as the Atmega 328 doesn't like digitalRead from A6 / A7 + * + */ + uint8_t gfDigitalRead(uint8_t buttonPin) + { + uint8_t pinState = 0; + if (buttonPin == A6 || buttonPin == A7) + { + return analogRead(buttonPin) > 10 ? 1 : 0; + } else { + return digitalRead(buttonPin); + } + } + + void setup() { + + // init serial port + Serial.begin(9600); + + // init Arduino LED + pinMode(ArduinoLED, OUTPUT); + + // Set proper pins to INPUT (INPUT_PULLUP NOT - eCog has pulldowns) + pinMode(eCogButton1, INPUT); + pinMode(eCogButton2, INPUT); + pinMode(eCogButton3, INPUT); + pinMode(eCogButton4, INPUT); + + } + + void loop() { + + digitalWrite(ArduinoLED, HIGH); + + Serial.print("Buttons: "); + Serial.print(gfDigitalRead(eCogButton1), DEC); + Serial.print(gfDigitalRead(eCogButton2), DEC); + Serial.print(gfDigitalRead(eCogButton3), DEC); + Serial.println(gfDigitalRead(eCogButton4), DEC); + + delay(500); + + /* + if (gfDigitalRead(eCogButton1) == HIGH) + { + Serial.println("FOO"); + } else { + Serial.println("BAR"); + } + */ + + digitalWrite(ArduinoLED, LOW); + delay(500); + + } + From 2387f1175ea6a0e7e57b1e3bd884f6aa17f9a25f Mon Sep 17 00:00:00 2001 From: emuDrache Date: Sun, 9 Apr 2017 16:33:10 +0200 Subject: [PATCH 2/7] Update and rename eCog106-Button-and-LED.ino to eCog106-Button-and-Serial.ino renamed file. added a comment --- ...{eCog106-Button-and-LED.ino => eCog106-Button-and-Serial.ino} | 1 + 1 file changed, 1 insertion(+) rename examples/eCogs/eCog106-Button-and-LED/{eCog106-Button-and-LED.ino => eCog106-Button-and-Serial.ino} (97%) diff --git a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino similarity index 97% rename from examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino rename to examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino index 56f6675..e3b2492 100644 --- a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino +++ b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino @@ -3,6 +3,7 @@ * * eCogs Used: * eCog106 - Button & LED - Connect to eCog D + * -- Outputs Status to Serial Port * * Libraries required (Install with Library Manager): * GadgetBox From 8d663d3c804e59b6f449b923586d49fce428e06a Mon Sep 17 00:00:00 2001 From: emuDrache Date: Sun, 9 Apr 2017 16:34:11 +0200 Subject: [PATCH 3/7] Update eCog106-Button-and-Serial.ino --- .../eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino index e3b2492..2024090 100644 --- a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino +++ b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino @@ -3,7 +3,7 @@ * * eCogs Used: * eCog106 - Button & LED - Connect to eCog D - * -- Outputs Status to Serial Port + * -- Outputs Status to Serial Port @ 9600 Baud * * Libraries required (Install with Library Manager): * GadgetBox From e050e920bf010708d86cf57599f5b8517d23539c Mon Sep 17 00:00:00 2001 From: emuDrache Date: Sun, 9 Apr 2017 17:33:37 +0200 Subject: [PATCH 4/7] Create eCog106-Button-and-LED.ino eCog106-Button-and-LED Example.. -- Holding Button 3 makes LED 4 blink fast -- Holding Button 2 makes LED 1 mimic the Arduino LED --- .../eCog106-Button-and-LED.ino | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino diff --git a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino new file mode 100644 index 0000000..cbed3cb --- /dev/null +++ b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino @@ -0,0 +1,113 @@ +/************************************************************** + * Use this sketch to test the Button and LED eCog + * + * eCogs Used: + * eCog106 - Button & LED - Connect to eCog D + * -- Holding Button 3 makes LED 4 blink fast + * -- Holding Button 2 makes LED 1 mimic the Arduino LED + * + * Libraries required (Install with Library Manager): + * GadgetBox + * + * GadgetBox Motherboards supported: + * Arduino Mini Pro + * + * + * Demo by emuDrache + * + **************************************************************/ + + #include + + #define eCogButton1 DC0 + #define eCogButton2 DC1 // analogRead Only Pin when in eCog C or D! (A6/GB9) + #define eCogButton3 DC2 // analogRead Only Pin when in eCog C or D! (A7/GB10) + #define eCogButton4 DC3 + + #define eCogLED1 DC0 + #define eCogLED2 DC1 // analogRead Only Pin when in eCog C or D! (A6/GB9) + #define eCogLED3 DC2 // analogRead Only Pin when in eCog C or D! (A7/GB10) + #define eCogLED4 DC3 + + + #define ArduinoLED 13 // Arduino soldered to Arduino Mini Pro + + /* + * + * Handles reading from the digital/analog pin mishmash, + * as the Atmega 328 doesn't like digitalRead from A6 / A7 + * + */ + uint8_t gfDigitalRead(uint8_t buttonPin) + { + uint8_t pinState = 0; + if (buttonPin == A6 || buttonPin == A7) + { + return analogRead(buttonPin) > 10 ? 1 : 0; + } else { + return digitalRead(buttonPin); + } + } + + /* + * + * Handles reading from the digital/analog pin mishmash, + * as the Atmega 328 doesn't like analogWrite to A6 / A7 + * + */ + void gfDigitalWrite(uint8_t buttonPin, pinState) + { + if (buttonPin == A6 || buttonPin == A7) + { + // just in case - lets do nothing. trying to write to A6/A7 pins crashed my arduino on occasion + // pinState == 1 ? analogWrite(buttonPin, 127) : analogWrite(pin, 0); + } else { + digitalWrite(buttonPin, pinState); + } + } + + void setup() { + + // init Arduino LED + pinMode(ArduinoLED, OUTPUT); + + // Set proper pins to INPUT/OUTPUT (INPUT_PULLUP NOT - eCog has pulldowns) + pinMode(eCogLED1, OUTPUT); + pinMode(eCogButton2, INPUT); + pinMode(eCogButton3, INPUT); + pinMode(eCogLED4, OUTPUT); + + } + + void loop() { + + digitalWrite(ArduinoLED, HIGH); + + // Make LED 4 blink if eCog Button 3 is held down + while (gfDigitalRead(eCogButton3)) + { + gfDigitalWrite(eCogLED4, HIGH); + delay(100); + gfDigitalWrite(eCogLED4, LOW); + delay(100); + } + + // Make LED 1 mimic Arduino LED if eCog Button 2 is held down + if (gfDigitalRead(eCogButton2)) + { + gfDigitalWrite(eCogLED1, HIGH); + } + + delay(500); + + digitalWrite(ArduinoLED, LOW); + + // Make LED 1 mimic Arduino LED if eCog Button 2 is held down + if (gfDigitalRead(eCogButton2)) + { + gfDigitalWrite(eCogLED1, LOW); + } + + delay(500); + + } From 7c6b86c6db1a5cade2d4110e1191471895c020d9 Mon Sep 17 00:00:00 2001 From: emuDrache Date: Sun, 9 Apr 2017 17:36:09 +0200 Subject: [PATCH 5/7] Update eCog106-Button-and-Serial.ino annotated that Arduino Mini Pro A6/A7 are usable only for analogRead (CC1 CC2 DC1 DC2 pins of C and D eCog slots) --- .../eCog106-Button-and-LED/eCog106-Button-and-Serial.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino index 2024090..dc96b10 100644 --- a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino +++ b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino @@ -19,8 +19,8 @@ #include #define eCogButton1 DC0 - #define eCogButton2 DC1 // Analog Only Pin! (A6/GB9) - #define eCogButton3 DC2 // Analog Only Pin! (A7/GB10) + #define eCogButton2 DC1 // analogRead Only Pin when in eCog C or D! (A6/GB9) + #define eCogButton3 DC2 // analogRead Only Pin when in eCog C or D! (A7/GB10) #define eCogButton4 DC3 #define ArduinoLED 13 // Arduino soldered to Arduino Mini Pro From 4aaafa0fecc74190e3631bfae12f6df97eab36ad Mon Sep 17 00:00:00 2001 From: emuDrache Date: Sun, 9 Apr 2017 17:39:28 +0200 Subject: [PATCH 6/7] Update eCog106-Button-and-Serial.ino --- .../eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino index dc96b10..b812521 100644 --- a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino +++ b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-Serial.ino @@ -3,7 +3,7 @@ * * eCogs Used: * eCog106 - Button & LED - Connect to eCog D - * -- Outputs Status to Serial Port @ 9600 Baud + * -- Outputs Button States to Serial Port @ 9600 Baud * * Libraries required (Install with Library Manager): * GadgetBox From ea955984fd82882e0418146dd35aa5ce2e859924 Mon Sep 17 00:00:00 2001 From: emuDrache Date: Sun, 9 Apr 2017 23:57:42 +0200 Subject: [PATCH 7/7] typo fix --- .../eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino index cbed3cb..6556216 100644 --- a/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino +++ b/examples/eCogs/eCog106-Button-and-LED/eCog106-Button-and-LED.ino @@ -55,7 +55,7 @@ * as the Atmega 328 doesn't like analogWrite to A6 / A7 * */ - void gfDigitalWrite(uint8_t buttonPin, pinState) + void gfDigitalWrite(uint8_t buttonPin, uint8_t pinState) { if (buttonPin == A6 || buttonPin == A7) { @@ -93,7 +93,7 @@ } // Make LED 1 mimic Arduino LED if eCog Button 2 is held down - if (gfDigitalRead(eCogButton2)) + if (gfDigitalRead(eCogButton2) == HIGH) { gfDigitalWrite(eCogLED1, HIGH); } @@ -103,7 +103,7 @@ digitalWrite(ArduinoLED, LOW); // Make LED 1 mimic Arduino LED if eCog Button 2 is held down - if (gfDigitalRead(eCogButton2)) + if (gfDigitalRead(eCogButton2) == HIGH) { gfDigitalWrite(eCogLED1, LOW); }