From d7a6f6f682bb6ef27cc336d8d62f37e613e0bff8 Mon Sep 17 00:00:00 2001 From: Gabriel Staples Date: Sat, 22 Oct 2016 15:06:47 -0400 Subject: [PATCH 1/5] various updates, comments improvements, etc ...in the process of updating code... --- TVB.pde => Arduino_TV_B_Gone.ino | 90 +++++++++++++++++------------- README => README.md | 6 ++ WORLDcodes.cpp => WORLD_IR_CODES.h | 9 +-- main.h | 28 ++++++---- 4 files changed, 78 insertions(+), 55 deletions(-) rename TVB.pde => Arduino_TV_B_Gone.ino (85%) rename README => README.md (74%) rename WORLDcodes.cpp => WORLD_IR_CODES.h (99%) diff --git a/TVB.pde b/Arduino_TV_B_Gone.ino similarity index 85% rename from TVB.pde rename to Arduino_TV_B_Gone.ino index efa2fc6..bdc65cf 100644 --- a/TVB.pde +++ b/Arduino_TV_B_Gone.ino @@ -1,36 +1,42 @@ /* +Last Updated: 22 Oct. 2016 +By Gabriel Staples, http://www.ElectricRCAircraftGuy.com +-My contact info is available by clicking the "Contact Me" tab at the top of my website. + TV-B-Gone for Arduino version 1.2, Oct 23 2010 -Ported to Arduino by Ken Shirriff= -http://www.arcfn.com/2009/12/tv-b-gone-for-arduino.html +Ported to Arduino by Ken Shirriff +See here: http://www.arcfn.com/2009/12/tv-b-gone-for-arduino.html +Circuit: +-NB: SEE "main.h" TO VERIFY DEFINED PINS TO USE The hardware for this project uses an Arduino: - Connect an IR LED to pin 3 (RLED). - Connect a visible LED to pin 13 (or use builtin LED in some Arduinos). + Connect an IR LED to pin 3 (IRLED). + Connect a visible LED to the pin 13 (or use the built-in LED in many Arduinos). Connect a pushbutton between pin 2 (TRIGGER) and ground. - Pin 5 (REGIONSWITCH) is floating for North America, or wired to ground for Europe. - + Pin 5 (REGIONSWITCH) must be left floating for North America, or wired to ground for Europe. + Pin 12 is a debug pin (DBG) + +I added universality for EU (European Union) or NA (North America), +and Sleep mode to Ken's Arduino port + -- Mitch Altman 18-Oct-2010 +Thanks to ka1kjz for the code for adding Sleep + + The original code is: TV-B-Gone Firmware version 1.2 for use with ATtiny85v and v1.2 hardware (c) Mitch Altman + Limor Fried 2009 Last edits, August 16 2009 +With some code from: +Kevin Timmerman & Damien Good 7-Dec-07 - I added universality for EU or NA, - and Sleep mode to Ken's Arduino port - -- Mitch Altman 18-Oct-2010 - Thanks to ka1kjz for the code for adding Sleep - - +LICENSE: +Distributed under Creative Commons 2.5 -- Attribution & Share Alike - With some code from: - Kevin Timmerman & Damien Good 7-Dec-07 +*/ - Distributed under Creative Commons 2.5 -- Attib & Share Alike - - */ - -#include "main.h" +#include "WORLD_IR_CODES.h" #include void xmitCodeElement(uint16_t ontime, uint16_t offtime, uint8_t PWM_code ); @@ -75,8 +81,8 @@ This project transmits a bunch of TV POWER codes, one right after the other, This project is a good example of how to use the AVR chip timers. */ -extern PGM_P *NApowerCodes[] PROGMEM; -extern PGM_P *EUpowerCodes[] PROGMEM; +extern const PGM_P * const NApowerCodes[] PROGMEM; +extern const PGM_P * const EUpowerCodes[] PROGMEM; extern uint8_t num_NAcodes, num_EUcodes; /* This function is the 'workhorse' of transmitting IR codes. @@ -178,7 +184,7 @@ The C compiler creates code that will transfer all constants into RAM when */ uint16_t ontime, offtime; -uint8_t i,num_codes, Loop; +uint8_t i,num_codes; uint8_t region; uint8_t startOver; @@ -197,12 +203,10 @@ void setup() { pinMode(LED, OUTPUT); pinMode(IRLED, OUTPUT); pinMode(DBG, OUTPUT); // debug - pinMode(REGIONSWITCH, INPUT); - pinMode(TRIGGER, INPUT); - digitalWrite(REGIONSWITCH, HIGH); //Pull-up - digitalWrite(TRIGGER, HIGH); + pinMode(REGIONSWITCH, INPUT_PULLUP); + pinMode(TRIGGER, INPUT_PULLUP); - delay_ten_us(5000); // Let everything settle for a bit + delay_ten_us(5000); //50ms (5000x10 us) delay: let everything settle for a bit // determine region if (digitalRead(REGIONSWITCH)) { @@ -227,6 +231,7 @@ void setup() { delay_ten_us(65500); // wait maxtime delay_ten_us(65500); // wait maxtime delay_ten_us(65500); // wait maxtime + quickflashLEDx(3); if (region == EU) { quickflashLEDx(3); @@ -238,7 +243,7 @@ Start_transmission: // startOver will become TRUE if the user pushes the Trigger button while transmitting the sequence of all codes startOver = FALSE; - // determine region from REGIONSWITCH: 1 = NA, 0 = EU + // determine region from REGIONSWITCH: 1 = NA, 0 = EU (defined in main.h) if (digitalRead(REGIONSWITCH)) { region = NA; num_codes = num_NAcodes; @@ -249,7 +254,8 @@ Start_transmission: } // for every POWER code in our collection - for (i=0 ; i < num_codes; i++) { + for (i=0 ; i +/* +Last Updated: 22 Oct. 2016 +By Gabriel Staples, http://www.ElectricRCAircraftGuy.com +-My contact info is available by clicking the "Contact Me" tab at the top of my website. +*/ +#include -// The TV-B-Gone for Arduino can use -// either the EU or the NA database of POWER CODES +// The TV-B-Gone for Arduino can use either the EU (European Union) or the NA (North America) database of POWER CODES // EU is for Europe, Middle East, Australia, New Zealand, and some countries in Africa and South America // NA is for North America, Asia, and the rest of the world not covered by EU // Two regions! -#define NA 1 -#define EU 0 +#define NA 1 //set by a HIGH on REGIONSWITCH pin +#define EU 0 //set by a LOW on REGIONSWITCH pin // What pins do what -#define DBG 12 -#define LED 13 -#define IRLED 3 -#define TRIGGER 2 -#define REGIONSWITCH 5 +#define DBG 12 //debug pin +#define LED LED_BUILTIN //LED pin (usually 13) +#define IRLED 3 //the IR LED +#define TRIGGER 2 //the button pin; NB: this pin is "hard-coded" in the sleepNow() function in the primary .ino file by means of using external interrupt 0, which is hard-wired to pin 2 +#define REGIONSWITCH 5 //HIGH (1) = NA, LOW (0) = EU; Pin 5 (REGIONSWITCH) is HIGH (via in input pullup resistor) for North America, or wired to ground for Europe. // Lets us calculate the size of the NA/EU databases #define NUM_ELEM(x) (sizeof (x) / sizeof (*(x))); @@ -28,6 +32,8 @@ #define NOP __asm__ __volatile__ ("nop") // Tweak this if neccessary to change timing +// -for 8MHz Arduinos, a good starting value is 11 +// -for 16MHz Arduinos, a good starting value is 25 #define DELAY_CNT 25 // Makes the codes more readable. the OCRA is actually @@ -41,5 +47,5 @@ struct IrCode { uint8_t numpairs; uint8_t bitcompression; uint16_t const *times; - uint8_t const*codes; + uint8_t const *codes; }; From 5a464589a624ec1f1ddd2aa8de3745d92e5bc9e2 Mon Sep 17 00:00:00 2001 From: Gabriel Staples Date: Sat, 22 Oct 2016 17:06:44 -0400 Subject: [PATCH 2/5] Updated to v1.3--works w/new gcc now--PROGMEM fixed --- Arduino_TV_B_Gone.ino | 55 ++++++++++++++++----------- README.md | 86 +++++++++++++++++++++++++++++++------------ WORLD_IR_CODES.h | 11 ++++-- main.h | 9 ++--- 4 files changed, 107 insertions(+), 54 deletions(-) diff --git a/Arduino_TV_B_Gone.ino b/Arduino_TV_B_Gone.ino index bdc65cf..644b974 100644 --- a/Arduino_TV_B_Gone.ino +++ b/Arduino_TV_B_Gone.ino @@ -3,19 +3,20 @@ Last Updated: 22 Oct. 2016 By Gabriel Staples, http://www.ElectricRCAircraftGuy.com -My contact info is available by clicking the "Contact Me" tab at the top of my website. +------------------------------------------------------------ +Semver (http://semver.org/) VERSION HISTORY (newest on top): +(date format: yyyymmdd; ex: 20161022 is 22 Oct. 2016) +------------------------------------------------------------ +-20161022 - v1.3 - Semver versioning implemented; various code updates, clarifications, & comment additions, and changes to fix PROGMEM incompatibilities so it will now compile with latest versions of gcc compiler; also implemented a few new blink indicator routines//////////; by Gabriel Staples (http://www.ElectricRCAircraftGuy.com) +-20101023 - v1.2 - Latest version posted by Ken Shirriff on his website here (http://www.righto.com/2010/11/improved-arduino-tv-b-gone.html) (direct download link here: http://arcfn.com/files/arduino-tv-b-gone-1.2.zip) +-20101018 - v1.2 - Universality for EU (European Union) & NA (North America) added by Mitch Altman; sleep mode added by ka1kjz +-2010____ - v1.2 - code ported to Arduino; by Ken Shirriff +-20090816 - v1.2 - for ATtiny85v, by Mitch Altman & Limor Fried (https://www.adafruit.com/), w/some code by Kevin Timmerman & Damien Good + TV-B-Gone for Arduino version 1.2, Oct 23 2010 Ported to Arduino by Ken Shirriff -See here: http://www.arcfn.com/2009/12/tv-b-gone-for-arduino.html +See here: http://www.arcfn.com/2009/12/tv-b-gone-for-arduino.html and here: http://www.righto.com/2010/11/improved-arduino-tv-b-gone.html (newer) -Circuit: --NB: SEE "main.h" TO VERIFY DEFINED PINS TO USE -The hardware for this project uses an Arduino: - Connect an IR LED to pin 3 (IRLED). - Connect a visible LED to the pin 13 (or use the built-in LED in many Arduinos). - Connect a pushbutton between pin 2 (TRIGGER) and ground. - Pin 5 (REGIONSWITCH) must be left floating for North America, or wired to ground for Europe. - Pin 12 is a debug pin (DBG) - I added universality for EU (European Union) or NA (North America), and Sleep mode to Ken's Arduino port -- Mitch Altman 18-Oct-2010 @@ -31,7 +32,19 @@ TV-B-Gone Firmware version 1.2 With some code from: Kevin Timmerman & Damien Good 7-Dec-07 +------------------------------------------------------------ +CIRCUIT: +------------------------------------------------------------ +-NB: SEE "main.h" TO VERIFY DEFINED PINS TO USE +The hardware for this project uses an Arduino: + Connect an IR LED to pin 3 (IRLED). + Connect a visible LED to the pin 13 (or use the built-in LED in many Arduinos). + Connect a push-button between pin 2 (TRIGGER) and ground. + Pin 5 (REGIONSWITCH) must be left floating for North America, or wire it to ground to have it output European codes. + +------------------------------------------------------------ LICENSE: +------------------------------------------------------------ Distributed under Creative Commons 2.5 -- Attribution & Share Alike */ @@ -81,8 +94,8 @@ This project transmits a bunch of TV POWER codes, one right after the other, This project is a good example of how to use the AVR chip timers. */ -extern const PGM_P * const NApowerCodes[] PROGMEM; -extern const PGM_P * const EUpowerCodes[] PROGMEM; +extern const IrCode* const NApowerCodes[] PROGMEM; +extern const IrCode* const EUpowerCodes[] PROGMEM; extern uint8_t num_NAcodes, num_EUcodes; /* This function is the 'workhorse' of transmitting IR codes. @@ -199,10 +212,8 @@ void setup() { digitalWrite(LED, LOW); digitalWrite(IRLED, LOW); - digitalWrite(DBG, LOW); // debug pinMode(LED, OUTPUT); pinMode(IRLED, OUTPUT); - pinMode(DBG, OUTPUT); // debug pinMode(REGIONSWITCH, INPUT_PULLUP); pinMode(TRIGGER, INPUT_PULLUP); @@ -232,10 +243,10 @@ void setup() { delay_ten_us(65500); // wait maxtime delay_ten_us(65500); // wait maxtime - quickflashLEDx(3); - if (region == EU) { + if (region == NA) quickflashLEDx(3); - } + else //region == EU + quickflashLEDx(6); } void sendAllCodes() { @@ -314,8 +325,8 @@ Start_transmission: // transmitting offTime means no output from the IR emitters for the // length of time specified in offTime +//DEV TESTING: #if 0 - // print out all of the pulse pairs for (uint8_t k=0; k +For information on the original TV-B-Gone see: +http://www.tvbgone.com/cfe_tvbg_main.php +The original code is: +TV-B-Gone Firmware version 1.2 + for use with ATtiny85v and v1.2 hardware + (c) Mitch Altman + Limor Fried 2009 + Last edits, August 16 2009 + +Added universality for EU or NA, +and Sleep mode to Ken's Arduino port + -- Mitch Altman 18-Oct-2010 +Thanks to ka1kjz for the code for adding Sleep + + +With some code from: +Kevin Timmerman & Damien Good 7-Dec-07 + +# License: +Distributed under Creative Commons 2.5 -- Attribution & Share Alike + +# CIRCUIT: +-NB: SEE "main.h" TO VERIFY DEFINED PINS TO USE +The hardware for this project uses an Arduino: + Connect an IR LED to pin 3 (IRLED). + Connect a visible LED to the pin 13 (or use the built-in LED in many Arduinos). + Connect a push-button between pin 2 (TRIGGER) and ground. + Pin 5 (REGIONSWITCH) must be left floating for North America, or wire it to ground to have it output European codes. + +# User Manual: +## Background Settings: + * The TV-B-Gone for Arduino can use either the EU (European Union) or the NA (North America) database of POWER CODES + * EU is for Europe, Middle East, Australia, New Zealand, and some countries in Africa and South America + * NA is for North America, Asia, and the rest of the world not covered by EU + * Let pin 5 float for NA codes, or wire it to ground to have it send EU codes + * Serial debugging output can be activated by setting "DEBUG 0" to "DEBUG 1" in "main.h" + * For 8 MHz Arduinos, define DELAY_CNT as 11 in "main.h," or use 25 for 16 MHz Arduinos. + * Fine-tune if necessary + * All IR codes are defined in "WORLD_IR_CODES.h" + * We'd love to have you add more! Just be careful NOT to duplicate codes please! +## Use: + * When the device is first powered on, it will quick-flash (30ms on followed by 150ms off) 3 times if set to output NA (North America) codes, or 6 times for EU (European Union) codes. See the end of the "setup()" function. + * Once on, the device will enter sleep mode, where it will remain until a button press occurs on the TRIGGER pin, at which point it will wake up and send all of its power codes for the region set according to the state of the REGIONSWITCH pin. + * Once you press the TRIGGER button (on pin 2), all power codes will be sent sequentially, one after the other. Note that the trigger button debouncing is done in a very primitive fashion, so quick button presses and releases (<200ms) may work best. + * Once all codes have been sent (may take around a minute or so), 8 quick flashes will occur to indicate that all power codes have been sent, then the device will go back into sleep mode until another TRIGGER button press occurs. + * Between individual power codes, the TRIGGER button is read one time. If it is read as pressed (LOW), it will restart the power code sequence from the beginning. This will be indicated by a ~705ms delay followed by 4 quick-flashes. Since the TRIGGER button is only read between individual codes, rather than continuously, you may need to hold down the button for a half-second to second or so for it to be read properly as pressed. Once the delay and 4 quick-flashes begin, you can release the button. The power codes will restart. - With some code from: - Kevin Timmerman & Damien Good 7-Dec-07 - Distributed under Creative Commons 2.5 -- Attib & Share Alike -User Manual: --When the device is first plugged in, Tell the user what region we're in - 3 flashes is NA, 6 is EU diff --git a/WORLD_IR_CODES.h b/WORLD_IR_CODES.h index 4b35da7..a71ded7 100644 --- a/WORLD_IR_CODES.h +++ b/WORLD_IR_CODES.h @@ -11,7 +11,7 @@ TV-B-Gone Firmware version 1.2 */ //Codes captured from Generation 3 TV-B-Gone by Limor Fried & Mitch Altman -// table of POWER codes +//table of POWER codes #include "main.h" @@ -8503,8 +8503,11 @@ const struct IrCode code_eu139Code PROGMEM = { //////////////////////////////////////////////////////////////// -//PROGMEM array of const pointers to IrCode structs (I think) -const struct IrCode * const NApowerCodes[] PROGMEM = { +//const PROGMEM array (called "NApowerCodes") of const pointers to IrCode structs +//-otherwise stated: "declare NApowerCodes as PROGMEM array of const pointers to const IrCode structs" +//-to confirm this, go to http://cdecl.org/ and paste "const int* const NApowerCodes[]", and you'll +// see it means "declare NApowerCodes as array of const pointer to const int" +const IrCode* const NApowerCodes[] PROGMEM = { &code_na000Code, &code_na001Code, &code_na002Code, @@ -8644,7 +8647,7 @@ const struct IrCode * const NApowerCodes[] PROGMEM = { &code_na136Code, }; -const struct IrCode * const EUpowerCodes[] PROGMEM = { +const IrCode* const EUpowerCodes[] PROGMEM = { &code_eu000Code, &code_eu001Code, &code_eu002Code, diff --git a/main.h b/main.h index 3ac37e0..d603c75 100644 --- a/main.h +++ b/main.h @@ -15,11 +15,10 @@ By Gabriel Staples, http://www.ElectricRCAircraftGuy.com #define EU 0 //set by a LOW on REGIONSWITCH pin // What pins do what -#define DBG 12 //debug pin -#define LED LED_BUILTIN //LED pin (usually 13) -#define IRLED 3 //the IR LED -#define TRIGGER 2 //the button pin; NB: this pin is "hard-coded" in the sleepNow() function in the primary .ino file by means of using external interrupt 0, which is hard-wired to pin 2 -#define REGIONSWITCH 5 //HIGH (1) = NA, LOW (0) = EU; Pin 5 (REGIONSWITCH) is HIGH (via in input pullup resistor) for North America, or wired to ground for Europe. +#define LED LED_BUILTIN //LED indicator pin (usually 13) +#define IRLED 3 //the IR sender LED +#define TRIGGER 2 //the button pin; NB: this pin is "hard-coded" in the sleepNow() function in the primary .ino file by means of using external interrupt 0, which is hard-wired to pin 2 +#define REGIONSWITCH 5 //HIGH (1) = NA, LOW (0) = EU; Pin 5 (REGIONSWITCH) is HIGH (via in input pullup resistor) for North America, or you (the user) must wire it to ground to set the codes for Europe. // Lets us calculate the size of the NA/EU databases #define NUM_ELEM(x) (sizeof (x) / sizeof (*(x))); From 67c8db904231f43a0454b6fc958b2ee3daea1687 Mon Sep 17 00:00:00 2001 From: Gabriel Staples Date: Sat, 22 Oct 2016 17:54:22 -0400 Subject: [PATCH 3/5] messing with button presses & functions --- Arduino_TV_B_Gone.ino | 55 +++++++++++++++++++++++++------------------ README.md | 36 +++++++++++++++------------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/Arduino_TV_B_Gone.ino b/Arduino_TV_B_Gone.ino index 644b974..d8b758b 100644 --- a/Arduino_TV_B_Gone.ino +++ b/Arduino_TV_B_Gone.ino @@ -196,13 +196,14 @@ The C compiler creates code that will transfer all constants into RAM when const PGM_P time_ptr = (PGM_P)pgm_read_word(code_ptr); */ +#define FALSE 0 +#define TRUE 1 +#define BUTTON_PRESSED 0 + uint16_t ontime, offtime; uint8_t i,num_codes; uint8_t region; -uint8_t startOver; - -#define FALSE 0 -#define TRUE 1 +bool startOver = FALSE; void setup() { Serial.begin(9600); @@ -251,8 +252,6 @@ void setup() { void sendAllCodes() { Start_transmission: - // startOver will become TRUE if the user pushes the Trigger button while transmitting the sequence of all codes - startOver = FALSE; // determine region from REGIONSWITCH: 1 = NA, 0 = EU (defined in main.h) if (digitalRead(REGIONSWITCH)) { @@ -372,18 +371,31 @@ Start_transmission: // delay 205 milliseconds before transmitting next POWER code delay_ten_us(20500); - // if user is pushing (holding down) Trigger button, stop transmission & start over at the 1st code again - if (digitalRead(TRIGGER) == 0) { - startOver = TRUE; - delay_ten_us(50000); //500ms delay - quickflashLEDx(4); - break; //exit the POWER code for loop + // if user is pushing (holding down) TRIGGER button, stop transmission & start over at the 1st code again + // -if user is holding down the TRIGGER button for an extended period of time, stop the code-sending sequence entirely + if (digitalRead(TRIGGER) == BUTTON_PRESSED) + { + if (startOver==TRUE) + { + //if startOver was already TRUE, it means the button has been pressed for 2 cycles in a row, so let's stop + startOver = FALSE; //update + break; //exit the POWER code "for" loop + } + else //startOver==FALSE, so let's start over now + { + startOver = TRUE; + delay_ten_us(50000); //500ms delay + quickflashLEDx(4); + break; //exit the POWER code "for" loop + } } } //end of POWER code for loop - if (startOver) goto Start_transmission; + if (startOver) + goto Start_transmission; - // flash the visible LED on PB0 8 times to indicate that we're done + //Otherwise, we are done (either because we were stopped early, or because we finished all the codes) + //-so, flash the visible LED 8 times to indicate that we're done delay_ten_us(65500); // wait maxtime delay_ten_us(65500); // wait maxtime quickflashLEDx(8); @@ -393,14 +405,11 @@ void loop() { sleepNow(); //Super "ghetto" (but decent enough for this application) button debouncing: - //-if the user pushes the Trigger button and lets go, then start transmission of all POWER codes - if (digitalRead(TRIGGER) == LOW) + //-if the user pushes the Trigger button, then wait a while to let the button stop bouncing, then start transmission of all POWER codes + if (digitalRead(TRIGGER) == BUTTON_PRESSED) { - delay_ten_us(20000); // delay 200ms - if (digitalRead(TRIGGER) == HIGH) - { - sendAllCodes(); - } + delay_ten_us(25000); // delay 250ms + sendAllCodes(); } } @@ -434,7 +443,7 @@ void delay_ten_us(uint16_t us) { // This will indicate to the user that a code is being transmitted void quickflashLED( void ) { digitalWrite(LED, HIGH); - delay_ten_us(3000); // 30 millisec delay + delay_ten_us(3000); // 30 ms ON-time delay digitalWrite(LED, LOW); } @@ -443,7 +452,7 @@ void quickflashLED( void ) { void quickflashLEDx( uint8_t x ) { quickflashLED(); while(--x) { - delay_ten_us(15000); // 150 millisec delay between flahes + delay_ten_us(25000); // 250 ms OFF-time delay between flashes quickflashLED(); } } diff --git a/README.md b/README.md index 8961261..2f229ab 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ For background details on the Arduino port, how to build it, and how to use it, * http://www.righto.com/2010/11/improved-arduino-tv-b-gone.html (newer) For information on the original TV-B-Gone see: -http://www.tvbgone.com/cfe_tvbg_main.php +http://www.tvbgone.com/. Mitch Altman is the inventor of the original TV-B-Gone. The original code is: TV-B-Gone Firmware version 1.2 @@ -30,25 +30,24 @@ TV-B-Gone Firmware version 1.2 (c) Mitch Altman + Limor Fried 2009 Last edits, August 16 2009 -Added universality for EU or NA, -and Sleep mode to Ken's Arduino port - -- Mitch Altman 18-Oct-2010 -Thanks to ka1kjz for the code for adding Sleep - +Added universality for EU or NA, and Sleep mode to Ken's Arduino port. + -- Mitch Altman 18-Oct-2010 +Thanks to ka1kjz for the code for adding Sleep + -With some code from: -Kevin Timmerman & Damien Good 7-Dec-07 +With some code from: +Kevin Timmerman & Damien Good 7-Dec-07 # License: -Distributed under Creative Commons 2.5 -- Attribution & Share Alike +Distributed under Creative Commons 2.5 -- Attribution & Share Alike # CIRCUIT: -NB: SEE "main.h" TO VERIFY DEFINED PINS TO USE The hardware for this project uses an Arduino: - Connect an IR LED to pin 3 (IRLED). - Connect a visible LED to the pin 13 (or use the built-in LED in many Arduinos). - Connect a push-button between pin 2 (TRIGGER) and ground. - Pin 5 (REGIONSWITCH) must be left floating for North America, or wire it to ground to have it output European codes. + * Connect an IR LED to pin 3 (IRLED). + * Connect a visible LED to the pin 13 (or use the built-in LED in many Arduinos). + * Connect a push-button between pin 2 (TRIGGER) and ground. + * Pin 5 (REGIONSWITCH) must be left floating for North America, or wire it to ground to have it output European codes. # User Manual: ## Background Settings: @@ -61,12 +60,15 @@ The hardware for this project uses an Arduino: * Fine-tune if necessary * All IR codes are defined in "WORLD_IR_CODES.h" * We'd love to have you add more! Just be careful NOT to duplicate codes please! + ## Use: - * When the device is first powered on, it will quick-flash (30ms on followed by 150ms off) 3 times if set to output NA (North America) codes, or 6 times for EU (European Union) codes. See the end of the "setup()" function. - * Once on, the device will enter sleep mode, where it will remain until a button press occurs on the TRIGGER pin, at which point it will wake up and send all of its power codes for the region set according to the state of the REGIONSWITCH pin. - * Once you press the TRIGGER button (on pin 2), all power codes will be sent sequentially, one after the other. Note that the trigger button debouncing is done in a very primitive fashion, so quick button presses and releases (<200ms) may work best. + * When the device is first powered on, it will quick-flash (30ms on followed by 150ms off) 3 times if set to output NA (North America) codes, or 6 times for EU (European Union) codes. See the end of the "setup()" function. + * Once on, the device will enter sleep mode, where it will remain until a button press occurs on the TRIGGER pin, at which point it will wake up and send all of its power codes for the region set according to the state of the REGIONSWITCH pin. + * Once you press the TRIGGER button (on pin 2), all power codes will be sent sequentially, one after the other. Note that the trigger button debouncing is done in a very primitive fashion, so quick button presses and releases (<200ms) may work best. * Once all codes have been sent (may take around a minute or so), 8 quick flashes will occur to indicate that all power codes have been sent, then the device will go back into sleep mode until another TRIGGER button press occurs. - * Between individual power codes, the TRIGGER button is read one time. If it is read as pressed (LOW), it will restart the power code sequence from the beginning. This will be indicated by a ~705ms delay followed by 4 quick-flashes. Since the TRIGGER button is only read between individual codes, rather than continuously, you may need to hold down the button for a half-second to second or so for it to be read properly as pressed. Once the delay and 4 quick-flashes begin, you can release the button. The power codes will restart. + * Between individual power codes, the TRIGGER button is read one time. If it is read as pressed (LOW), it will restart the power code sequence from the beginning. This will be indicated by a ~705ms delay followed by 4 quick-flashes. Since the TRIGGER button is only read between individual codes, rather than continuously, you may need to hold down the button for a half-second to second or so for it to be read properly as pressed. Once the delay and 4 quick-flashes begin, you can release the button. The power codes will restart. If you hold the button down, it will simply continually restart the power codes, as indicated by the long pause followed by 4 quick-flashes, continuously repeated. + * To stop the power code sequence once it is started, you must disconnect power to your device. + * If you'd like a more sophisticated way to stop it, I can add proper button debouncing via my [eRCaGuy_ButtonReader](https://github.com/ElectricRCAircraftGuy/eRCaGuy_ButtonReader) library, then allow pressing the button to restart From 0f394f7d2ee672fda359010fe2b658ad5ff42bc2 Mon Sep 17 00:00:00 2001 From: Gabriel Staples Date: Sat, 22 Oct 2016 18:30:47 -0400 Subject: [PATCH 4/5] button and LED blink indicator code improved; readme updated --- Arduino_TV_B_Gone.ino | 71 ++++++++++++++++++------------------------- README.md | 14 ++++----- 2 files changed, 37 insertions(+), 48 deletions(-) diff --git a/Arduino_TV_B_Gone.ino b/Arduino_TV_B_Gone.ino index d8b758b..2c0e4f4 100644 --- a/Arduino_TV_B_Gone.ino +++ b/Arduino_TV_B_Gone.ino @@ -63,6 +63,8 @@ uint8_t read_bits(uint8_t count); #define putnum_ud(n) Serial.print(n, DEC) #define putnum_uh(n) Serial.print(n, HEX) +#define MAX_WAIT_TIME 65535 //tens of us (ie: 655.350ms) + /* This project transmits a bunch of TV POWER codes, one right after the other, with a pause in between each. (To have a visible indication that it is @@ -196,16 +198,14 @@ The C compiler creates code that will transfer all constants into RAM when const PGM_P time_ptr = (PGM_P)pgm_read_word(code_ptr); */ -#define FALSE 0 -#define TRUE 1 #define BUTTON_PRESSED 0 uint16_t ontime, offtime; uint8_t i,num_codes; uint8_t region; -bool startOver = FALSE; -void setup() { +void setup() +{ Serial.begin(9600); TCCR2A = 0; @@ -218,7 +218,7 @@ void setup() { pinMode(REGIONSWITCH, INPUT_PULLUP); pinMode(TRIGGER, INPUT_PULLUP); - delay_ten_us(5000); //50ms (5000x10 us) delay: let everything settle for a bit + delay_ten_us(5000); //50ms (5000x10 us) delay: let everything settle for a bit // determine region if (digitalRead(REGIONSWITCH)) { @@ -230,7 +230,7 @@ void setup() { DEBUGP(putstring_nl("EU")); } - // Indicate how big our database is + // Debug output: indicate how big our database is DEBUGP(putstring("\n\rNA Codesize: "); putnum_ud(num_NAcodes); ); @@ -239,20 +239,16 @@ void setup() { ); // Tell the user what region we're in - 3 flashes is NA, 6 is EU - delay_ten_us(65500); // wait maxtime - delay_ten_us(65500); // wait maxtime - delay_ten_us(65500); // wait maxtime - delay_ten_us(65500); // wait maxtime - if (region == NA) quickflashLEDx(3); else //region == EU quickflashLEDx(6); } -void sendAllCodes() { -Start_transmission: - +void sendAllCodes() +{ + bool endingEarly = false; //will be set to true if the user presses the button during code-sending + // determine region from REGIONSWITCH: 1 = NA, 0 = EU (defined in main.h) if (digitalRead(REGIONSWITCH)) { region = NA; @@ -324,7 +320,7 @@ Start_transmission: // transmitting offTime means no output from the IR emitters for the // length of time specified in offTime -//DEV TESTING: +//DEVELOPMENTAL TESTING: #if 0 // print out all of the pulse pairs for (uint8_t k=0; k Date: Sat, 22 Oct 2016 18:41:42 -0400 Subject: [PATCH 5/5] gitignore update --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..281b27a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +TV_B_Gone - Shortcut.lnk \ No newline at end of file