Pages: [1]   Go Down
Author Topic: PROGMEM.... store unsigned int ??  (Read 793 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
#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:
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!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 239
Posts: 24373
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
Logged

"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.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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!
« Last Edit: June 22, 2012, 09:29:11 am by jstone » Logged

Pages: [1]   Go Up
Jump to: