Go Down

Topic: PROGMEM.... store unsigned int ?? (Read 1 time) previous topic - next topic

jstone

Hi all,
im working on some ir remote control code.

I have it working using "unsigned int" but im guessing il soon run out of SRAM so i wanted to store my "unsigned int" to PROGMEM instead.

Here's the original code:

Code: [Select]
#include <IRremote.h>

IRsend irsend;

unsigned int chDWN[100]
= {
  4650,4450,550,450,600,400,600,400,600,450,550,1400,600,1400,600,450,550,450,600,400,600,1400,600,400,600,1400,600,1400,600,400,600,400,600,450,550,4450,600,400,600,450,550,450,600,400,600,400,600,1400,600,1400,600,400,600,450,550,450,600,1400,550,1450,550,1450,550,450,600,400,600,1400,600,1400,600,1400,550,450,600,400,600};

void setup()
{
  Serial.begin(9600);
}

void loop() {

  irsend.sendRaw(chDWN, 100, 12); // Channel down
  delay(2000);
  irsend.sendRaw(chDWN, 100, 12); // Channel down
  delay(2000);

}


But when i try to use PROGMEM i fail...

Code: [Select]
#include <avr/pgmspace.h>

#include <IRremote.h>

IRsend irsend;

PROGMEM  prog_uint16_t chUP[100]
= {
  4650,4450,550,450,600,400,600,400,600,450,550,1400,600,1400,600,450,550,450,600,400,600,1400,600,400,600,1400,600,1400,600,400,600,400,600,450,550,4450,600,400,600,450,550,450,600,400,600,400,600,1400,600,1400,600,400,600,450,550,450,600,1400,550,1450,550,1450,550,450,600,400,600,1400,600,1400,600,1400,550,450,600,400,600};

void setup()
{
  Serial.begin(9600);
}

void loop() {
 
  unsigned int chupInt;
  int k;    // counter variable
chupInt = pgm_read_word_near(chUP+ k);

  irsend.sendRaw(chupInt, 100, 12); // Channel down
  delay(2000);
  irsend.sendRaw(chupInt, 100, 12); // Channel down
  delay(2000);

}


Can anyone see what im doing wrong?

These are the errors i get..

Code: [Select]

IRsendDemo.cpp: In function 'void loop()':
IRsendDemo:21: error: invalid conversion from 'unsigned int' to 'unsigned int*'
IRsendDemo:21: error: initializing argument 1 of 'void IRsend::sendRaw(unsigned int*, int, int)'
IRsendDemo:23: error: invalid conversion from 'unsigned int' to 'unsigned int*'
IRsendDemo:23: error: initializing argument 1 of 'void IRsend::sendRaw(unsigned int*, int, int)'


Thanks!

AWOL

Code: [Select]
unsigned int chupInt;
  int k;    // counter variable
chupInt = pgm_read_word_near(chUP+ k);


A couple of things there; what's the value of "k"?

Quote
so i wanted to store my "unsigned int" to PROGMEM instead.

But it isn't an "unsigned int", it's an array of them, which is why the send fails.
You either have to rewrite the send function to use PROGMEM, or buffer the array in RAM.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

jstone

#2
Jun 22, 2012, 04:23 pm Last Edit: Jun 22, 2012, 04:29 pm by jstone Reason: 1
oooooo i see now.

So how would i go about rewriting the send function? via editing the library?
or how would i go about buffering the array in RAM?

Which ever is easiest..

I got the "K" from the PROGMEM arduino page "http://www.arduino.cc/en/Reference/PROGMEM"

I cant say i fully understand that myself.

This is what i think to be the send function in the Lib*

Code: [Select]
void IRsend::sendRaw(unsigned int buf[], int len, int hz)
{
  enableIROut(hz);
  for (int i = 0; i < len; i++) {
    if (i & 1) {
      space(buf[i]);
    }
    else {
      mark(buf[i]);
    }
  }
  space(0); // Just to be sure
}


Thanks Again!

Go Up