So I am trying to make an arduino based TV-B gone by this instructable:
Here is my wiring:
So my issue appears in Arduino.
When I first tried to verify the code I got an error saying I had to put const after the * in this code, both for EUpowerCodes and NApowerCodes:
"const struct IrCode *EUpowerCodes[] PROGMEM = {"
And So I filled out the const in the areas needed, but then I got this new error where there was an undefined reference to both EUpowerCodes and NApowerCodes. More specifically here's the error message:
Arduino:1.6.0 (Windows 8), Card "Arduino Uno"
TVB.cpp.o: In function `sendAllCodes()':
/Arduino/TVB.pde:261: undefined reference to `NApowerCodes'
/Arduino/TVB.pde:261: undefined reference to `NApowerCodes'
/Arduino/TVB.pde:264: undefined reference to `EUpowerCodes'
/Arduino/TVB.pde:264: undefined reference to `EUpowerCodes'
collect2: error: ld returned 1 exit status
Error by compiling.
The error occures at line 261 and 264, here I have the code from line 259 to 265:
259// point to next POWER code, from the right database
260 if (region == NA) {
261 data_ptr = (PGM_P)pgm_read_word(NApowerCodes+i);
262 }
263 else {
264 data_ptr = (PGM_P)pgm_read_word(EUpowerCodes+i);
265 }
Now I have tried putting "* cons" or just "const" in front of NApowerCodes and EUpowerCodes, and removing + i, and putting "const struct IrCode *EUpowerCodes[] PROGMEM = {" instead inside of the parenthesis.
Does anyone know what I did wrong or what I can add of code to fix this?
Attached is the TVB file with the undefined reference error.
Here is the code (I couldn't include the full code, but I have included what I think is most important. I have attached a file with the full file of the project if you want to take a look at that.
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
if (digitalRead(REGIONSWITCH)) {
region = NA;
num_codes = num_NAcodes;
}
else {
region = EU;
num_codes = num_EUcodes;
}
// for every POWER code in our collection
for (i=0 ; i < num_codes; i++) {
PGM_P data_ptr;
// print out the code # we are about to transmit
DEBUGP(putstring("\n\r\n\rCode #: ");
putnum_ud(i));
// point to next POWER code, from the right database
if (region == NA) {
data_ptr = (PGM_P)pgm_read_word(NApowerCodes+i);
}
else {
data_ptr = (PGM_P)pgm_read_word(EUpowerCodes+i);
}
// print out the address in ROM memory we're reading
DEBUGP(putstring("\n\rAddr: ");
putnum_uh((uint16_t)data_ptr));
// Read the carrier frequency from the first byte of code structure
const uint8_t freq = pgm_read_byte(data_ptr++);
// set OCR for Timer1 to output this POWER code's carrier frequency
OCR2A = freq;
OCR2B = freq / 3; // 33% duty cycle
// Print out the frequency of the carrier and the PWM settings
DEBUGP(putstring("\n\rOCR1: ");
putnum_ud(freq);
);
DEBUGP(uint16_t x = (freq+1) * 2;
putstring("\n\rFreq: ");
putnum_ud(F_CPU/x);
);
// Get the number of pairs, the second byte from the code struct
const uint8_t numpairs = pgm_read_byte(data_ptr++);
DEBUGP(putstring("\n\rOn/off pairs: ");
putnum_ud(numpairs));
// Get the number of bits we use to index into the timer table
// This is the third byte of the structure
const uint8_t bitcompression = pgm_read_byte(data_ptr++);
DEBUGP(putstring("\n\rCompression: ");
putnum_ud(bitcompression);
putstring("\n\r"));
// Get pointer (address in memory) to pulse-times table
// The address is 16-bits (2 byte, 1 word)
PGM_P time_ptr = (PGM_P)pgm_read_word(data_ptr);
data_ptr+=2;
code_ptr = (PGM_P)pgm_read_word(data_ptr);
// Transmit all codeElements for this POWER code
// (a codeElement is an onTime and an offTime)
// transmitting onTime means pulsing the IR emitters at the carrier
// frequency for the length of time specified in onTime
// transmitting offTime means no output from the IR emitters for the
// length of time specified in offTime
#if 0
tvb_file_with_undefined_reference 2.zip (22.2 KB)