3 * A recreation of the TV-B-Gone kit on an Arduino Duemilanove.
4 * By Daedalus12, mtbf0, westfw and Pedrocrespo
8 #include <avr/pgmspace.h>
11 uint32_t onTime; // duration of "On" time
12 uint32_t offTime; // duration of "Off" time
16 uint32_t freq; // frequency
17 struct codeElement codes[100]; // on/off codes, supposed to be 100 as maximum
20 int i = 0; // we use this for iterating
21 long cfreq; // we'll store each frequency here when needed
23 const struct powercode sonyCode PROGMEM = {
52 const struct powercode panasonicCode PROGMEM = {
156 const struct powercode sony2Code PROGMEM = {
216 const struct powercode sony3Code PROGMEM = {
275 PROGMEM const powercode *powerCodes[] = {
276 &sonyCode, &panasonicCode, &sony2Code, &sony3Code
277 }; // select the codes you like
279 int num_codes = (sizeof(powerCodes)/sizeof(*powerCodes)); // count how many codes are in the list
282 DDRD = _BV(DDD6); // sets Pin 6 as output
286 for(i=0;i<num_codes;i++){ //Iterate between powercodes
287 cfreq = pgm_read_word(pgm_read_word(&(powerCodes[i]))+0); // store the frequency
288 unsigned char compareVal = (F_CPU/cfreq - 1)/2; // transform it to cpu cycles
289 TCCR0A = 0; // make sure timer is off before updating OCR0A
290 OCR0A = compareVal; // update timer
291 for (int arrayStep = 0; pgm_read_word(pgm_read_word(&(powerCodes[i]))+(8*arrayStep)+8)!=0; arrayStep++){
292 transmitCode(pgm_read_word(pgm_read_word(&(powerCodes[i]))+(8*arrayStep)+4),pgm_read_word(pgm_read_word(&(powerCodes[i]))+(8*arrayStep)+8)); // transmit the code using function described below
294 delayMicroseconds(250);// Avoid interferring a powercode and the next one if frequencies are similar
298 void transmitCode(int onTime, int offTime){
299 // transmits one element of the POWER code
300 TCNT0 = 0; // reset timer 0
301 TCCR0A = _BV(COM0A0) | _BV(WGM01); // set up timer 0
302 TCCR0B = _BV(CS00); // turn on timer 0
303 delayMicroseconds(10*onTime); // wait for onTime
304 TCNT0 = 0; // stop timer
305 TCCR0A = 0; // clear register A
306 TCCR0B = 0; // clear register B
307 PORTD = ~_BV(PORTD6); // turn off the LED
308 delayMicroseconds(10*offTime); // wait for offTime