Pages: [1]   Go Down
Author Topic: Problem with array of objects  (Read 648 times)
0 Members and 1 Guest are viewing this topic.
Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I am working on making a planetarium with arduino. We have 3 arduino unos attached to LOL shields. I am trying to make constellations light up. I have a class in planet.h called stargroup
Code:
class stargroup

{
public:
        //constructors
    stargroup();
    stargroup(int, int[], int[]);
    stargroup& operator= (const stargroup &source);
   
        //patterns
    void fadeOn();
    void on();
    void fadeOff();
    void fadeOffAll();
    void off();
   
        //variables
    int xPos[16];
    int yPos[16];
    int noOfStars;
   
};

constructors are in planet.cpp
Code:
const int GLOBALDELAY = 100;


stargroup::stargroup()
{
    noOfStars = 0;
    xPos[16] = 0;
    yPos[16] =  0;
   
}

stargroup::stargroup(int x, int a[], int b[])
{
    noOfStars = x;
    for (int i = 0; i < noOfStars; i++)
    {
        xPos[i] = a[i];
        yPos[i] = b[i];
    }
    for (int i = noOfStars; i < 16; i++)
    {
        xPos[i] = 13;
        yPos[i] = 8;
    }
}


in my main arduino file, I declare an array of constellations as follows
Code:
stargroup con[23];
int xL[] = {2, 2 ,3, 3, 3, 3};//x positions
int yL[] = {1, 0, 8, 7, 6, 5};//y positions
stargroup L(6, xL, yL);      //no of stars, x, y
con[0] = L; //Set(L);

and then i go on to declare the other constellations. In the main loop I have a bit of code making all the lights twinkle.
the trouble seems to be with the declaration of the array of stargroup, no matter where I put it, it seems to not work. I have tried declaring it as global, in the set up and also in the main loop. the code compiles but none of the lights turn on. when the decleration is commented out, the lights come back on.

Any ideas why this could be? And what can I do to fix it? Thank you!
Logged

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

Code:
stargroup con[23]
Code:
int xPos[16];
    int yPos[16];
23 x 16 x 2 x 2 =1472.
Quote
and then i go on to declare the other constellations.

What other RAM usage do you have?
(It would have saved time if you'd posted all the code)
« Last Edit: August 17, 2012, 09:04:48 am by AWOL » 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.

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using new arrays to set lots of values at once
Code:
int xL[] = {2, 2 ,3, 3, 3, 3};
int yL[] = {1, 0, 8, 7, 6, 5};
stargroup L(6, xL, yL);
con[0] = L; //Set(L);

int xM[] = {3,3,3,3};
int yM[] = {4,3,2,1};
stargroup M(4, xM, yM);
con[1] = M; //Set(M);

int xN[] = {4,4,4,4};
int yN[] = {8,7,6,5};
stargroup N(4, xN, yN);
con[2] = N;

int xO[] = {4,4,4,4};
int yO[] = {4,3,2,1};
stargroup O(4, xO, yO);
con[3] = O;


do you think this is the problem? how should I get around this? Thanks
Logged

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

I think you may be running short of RAM, but without seeing all of your code, it is difficult to say.
You could cut down on wastage by dynamically allocating space for each object, or by using 8 bit variables if possible, instead of 16 bit.
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.

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

full code:
Code:

#include "Charliplexing.h"  //initializes the LoL Sheild library
#include "planet.h"


//#define colour "orange"
#define cons 23// how many constellations there are
 //orange = 23
 //pink = 20

int GLOBALDELAY = 100;
int scrollSpeed = 50;      //delay between frames


int xPosition = 0;          //x position 0-13
int yPosition = 0;          //y position 0-8
int frameCounter = 0;       //used to find when the frame has filled up (126 leds)
int greyscale = 1;          //greyscale color 0-7
bool set = true;

stargroup con[23];


void setup()                // run once, when the sketch starts
{
  LedSign::Init(GRAYSCALE); //initializes a grayscale frame buffer
 
 // if (colour == "orange")
 // {
 
//declaring the constella
int xL[] = {2, 2 ,3, 3, 3, 3};
int yL[] = {1, 0, 8, 7, 6, 5};
stargroup L(6, xL, yL);
con[0] = L; //Set(L);

int xM[] = {3,3,3,3};
int yM[] = {4,3,2,1};
stargroup M(4, xM, yM);
con[1] = M; //Set(M);

int xN[] = {4,4,4,4};
int yN[] = {8,7,6,5};
stargroup N(4, xN, yN);
con[2] = N;

int xO[] = {4,4,4,4};
int yO[] = {4,3,2,1};
stargroup O(4, xO, yO);
con[3] = O;

int xq[] = {5,5,5,5,5};
int yq[] = {7,6,5,4,3};
stargroup q(5, xq, yq);
con[4] = q; //Set(M);

int xe[] = {13, 13};
int ye[] = {8,7};
stargroup e(2, xe, ye);
con[5] = e; //Set(M);

int xf[] = {0,0,0,0,0};  //06 05 04 03 02
int yf[] = {6,5,4,3,2};
stargroup f(5, xf, yf);
con[6] = f; //Set(M);

int xg[] = {0,0,1,1};  //01 00 18 17
int yg[] = {1,0,8,7};
stargroup g(4, xg, yg);
con[7] = g; //Set(M);

int xh[] = {1,1,1,1,1}; 
int yh[] = {6,5,4,3,2};
stargroup h(5, xh, yh);
con[8] = h; //Set(M);

int xi[] = {1,4};  //10 48
int yi[] = {0,8};
stargroup i(2, xi, yi);
con[9] = i; //Set(M);

int xj[] = {2,2};  //27 26
int yj[] = {7,6};
stargroup j(2, xj, yj);
con[10] = j; //Set(M);

int xk[] = {2,2,2,2}; 
int yk[] = {5,4,3,2};
stargroup k(4, xk, yk);
con[11] = k; //Set(M);

int xa[] = {5,5,5,6,6,6};  //52 51 50 68 67 66
int ya[] = {2,1,0,8,7,6};
stargroup a(6, xa, ya);
con[12] = a; //Set(M);

int xb[] = {6,6,6,6}; 
int yb[] = {5,4,3,2};
stargroup b(4, xb, yb);
con[13] = b; //Set(M);

int xc[] = {6,6,7,7,7,7,7,7,7,7};  //61 60 78 77 76 75 74 73 72 71
int yc[] = {1,0,8,7,6,5,4,3,2,1};
stargroup c(10, xc, yc);
con[14] = c; //Set(M);

int xd[] = {7,8,8,8,8,8};  //06 05 04 03 02
int yd[] = {0,8,7,6,5,4};
stargroup d(6, xd, yd);
con[15] = d; //Set(M);

int xs[] = {8,8}; 
int ys[] = {3,2};
stargroup s(2, xs, ys);
con[16] = s; //Set(M);

int xt[] = {8,8,9,9}; 
int yt[] = {1,0,8,7};
stargroup t(4, xt, yt);
con[17] = t; //Set(M);

int xv[] = {9,9,9,9}; 
int yv[] = {6,5,4,3};
stargroup v(4, xv, yv);
con[18] = v; //Set(M);

int xw[] = {9,9,9,10,10,10};
int yw[] = {2,1,0,8,7,6};
stargroup w(6, xw, yw);
con[19] = w; //Set(M);

int xx[] = {10,10,10,10,10}; 
int yx[] = {5,4,3,2,1};
stargroup x(5, xx, yx);
con[20] = x; //Set(M);

int xy[] = {10, 11}; 
int yy[] = {0,8};
stargroup y(2, xy, yy);
con[21] = y; //Set(M);

int xz[] = {11,11,11}; 
int yz[] = {7,6,5};
stargroup z(3, xz, yz);
con[22] = z; //Set(M);


int xzz[] = {11,11}; 
int yzz[] = {4,3};
stargroup zz(2, xzz, yzz);
con[23] = zz;


}


void loop()                 // run over and over again
{
 // int count = 0; //used for timing
  bool up = true;  //up is used for twinkle direction.
  int lightup = 0; //used for which constellation is to be chosen.
 
 // stargroup con[20];         // array of constellations
 

// for (int k = 0; k < 10000; k++)
//  {
  //If the frame counter is full, then it delays for scrollSpeed.
    if(frameCounter == 126)
    {
      delay(scrollSpeed);
      frameCounter=0;
    //  LedSign::Set(random(13), random(8), random(7));
     // count++; 
    }
  //at the end of the row, it advances Y to the next one
  if(xPosition == 13)yPosition++;
  //at the end of the row, it starts from the first LED in the next one
  if(xPosition > 13)xPosition=0;
   //at the end of the frame, it starts from the begining again
  if(yPosition > 8)yPosition=0;
 

   
   //twinkle the lights between 2 and 6 so they dont turn off completly
  if(greyscale > 6) up = false;
  if(greyscale < 2) up = true;
  if (up) greyscale++;
  if (!up) greyscale--;
  // here are some variations for twinkles, but they are commented out

   // greyscale = random(7); //random (comment out increment above)
   // if(greyscale > 7)greyscale= 0;  // original
   //  if(greyscale > 7)greyscale= 4;   //light twinkle

  //sends the current x, y, and color to the frame, one LED at a time
  LedSign::Set(xPosition, yPosition, greyscale);  //set normal light to twinkle
  LedSign::Set(random(13), random(8), random(2,6)); //set random light to random value.


  //the counters are at the end of the loop, which will advance everything
  //for the next frame
  xPosition++;
  frameCounter++;
 // }
 
  for (int i = 0; i < cons; i++)
  {
    con[i].fadeOffAll();
  }
 
  delay(1000);
 
for (int i = 0; i < 5; i++)
{
  lightup = random(cons);
  con[lightup].fadeOn();
  delay(500);
  con[lightup].fadeOff();
  delay(500);
}
 
 
 // count = 0;
}




/////////////////////////////////////////







Logged

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

OK, it looks to me like all those "int" arrays could comfortably be "byte" arrays.
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.

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 3996
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should be making the array in PROGMEM (flash) instead of RAM and accessing through the special PROGMEM instructions.

I do this with my user-I/O menus and error messages even if I don't need just to stay in practice.

Examples ---

This just to show what HELPLINES and B (for byte) are:
Code:
#define  HELPLINES  7
byte B;

Declaring a multi-line Program Usage message to be stored in flash and then a pointer into flash:
Code:
const char PROGMEM usageMsg[][80] = { // all this text stored in flash
  "          Piezo touch sensor tuner.",
  "Adjust vertical; enter W to subtract or X to add, and a number 0-255",
  "Adjust timescaler; enter A to subtract or D to add, and 0-16535",
  "to add 250 to vertical enter W250 in Serial Monitor and press enter",
  "seperate multiple commands with spaces; ex: W25 D240",
  "    ** this message stored in flash ram **",
  "    ** and printed with a 1 byte buffer ** :-P"
};

PGM_P Msg; // pointer into flash memory

First function prints a single line of text from flash. Second function prints multiple lines.
Code:
void  printMsg( PGM_P FM )
{
  do
  {
    B = pgm_read_byte( FM++ );    // pgm_read_byte( PGM_P ) is the only special access I use
    if ( B )  Serial.print( B );          // but there are more to cover things like ints, etc.
  }                                               
  while ( B );
}

void printHelp(void)
{
  for ( byte i = 0; i < HELPLINES; i++ )
  {
    printMsg( usageMsg[ i ]);
    Serial.println();
  }
  Serial.println();
}

PROGMEM doc page over at AVR_Libc -- the home of the C/C++ Arduino uses:
http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html


Logged

Examples can be found in your IDE.

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, so I have changed a couple of things and it is still not working.
The program compiles, uploads but no code comes on.
@AWOL I tried having byte arrays, but the same thing happens.
@GoForSmoke I currently have it in progmem, but still nothing is happening.

Binary sketch size: 10,190 bytes (of a 32,256 byte maximum)

Any ideas on how to fix this?

here is all of my code:

orangeLOL:
Code:
/*
  Orange section of planetarium, twinkle the stars then show constellations. not working as of 6pm 18/8
*/

#include "Charliplexing.h"  //initializes the LoL Sheild library
#include "planet.h"
#include <avr/pgmspace.h>

//#define colour "orange"
#define cons 23// how many constellations there are
 //orange = 23
 //pink = 20

int GLOBALDELAY = 100;
int scrollSpeed = 50;      //delay between frames


int xPosition = 0;          //x position 0-13
int yPosition = 0;          //y position 0-8
int frameCounter = 0;       //used to find when the frame has filled up (126 leds)
int greyscale = 1;          //greyscale color 0-7
bool set = true;

  stargroup con[23];


void setup()                // run once, when the sketch starts
{
    Serial.begin(9600);
Serial.print(" start set up ");


  LedSign::Init(GRAYSCALE); //initializes a grayscale frame buffer
  
 // if (colour == "orange")
 // {
  
//declaring the constella
prog_int16_t xL[] = {2, 2 ,3, 3, 3, 3};
prog_int16_t yL[] = {1, 0, 8, 7, 6, 5};
stargroup L(6, xL, yL);
con[0] = L; //Set(L);

prog_int16_t xM[] = {3,3,3,3};
prog_int16_t yM[] = {4,3,2,1};
stargroup M(4, xM, yM);
con[1] = M; //Set(M);

prog_int16_t xN[] = {4,4,4,4};
prog_int16_t yN[] = {8,7,6,5};
stargroup N(4, xN, yN);
con[2] = N;

prog_int16_t xO[] = {4,4,4,4};
prog_int16_t yO[] = {4,3,2,1};
stargroup O(4, xO, yO);
con[3] = O;

prog_int16_t xq[] = {5,5,5,5,5};
prog_int16_t yq[] = {7,6,5,4,3};
stargroup q(5, xq, yq);
con[4] = q; //Set(M);

prog_int16_t xe[] = {13, 13};
prog_int16_t ye[] = {8,7};
stargroup e(2, xe, ye);
con[5] = e; //Set(M);

prog_int16_t xf[] = {0,0,0,0,0};  //06 05 04 03 02
prog_int16_t yf[] = {6,5,4,3,2};
stargroup f(5, xf, yf);
con[6] = f; //Set(M);

prog_int16_t xg[] = {0,0,1,1};  //01 00 18 17
prog_int16_t yg[] = {1,0,8,7};
stargroup g(4, xg, yg);
con[7] = g; //Set(M);

prog_int16_t xh[] = {1,1,1,1,1};  
prog_int16_t yh[] = {6,5,4,3,2};
stargroup h(5, xh, yh);
con[8] = h; //Set(M);

prog_int16_t xi[] = {1,4};  //10 48
prog_int16_t yi[] = {0,8};
stargroup i(2, xi, yi);
con[9] = i; //Set(M);

prog_int16_t xj[] = {2,2};  //27 26
prog_int16_t yj[] = {7,6};
stargroup j(2, xj, yj);
con[10] = j; //Set(M);

prog_int16_t xk[] = {2,2,2,2};  
prog_int16_t yk[] = {5,4,3,2};
stargroup k(4, xk, yk);
con[11] = k; //Set(M);

prog_int16_t xa[] = {5,5,5,6,6,6};  //52 51 50 68 67 66
prog_int16_t ya[] = {2,1,0,8,7,6};
stargroup a(6, xa, ya);
con[12] = a; //Set(M);

prog_int16_t xb[] = {6,6,6,6};  
prog_int16_t yb[] = {5,4,3,2};
stargroup b(4, xb, yb);
con[13] = b; //Set(M);

prog_int16_t xc[] = {6,6,7,7,7,7,7,7,7,7};  //61 60 78 77 76 75 74 73 72 71
prog_int16_t yc[] = {1,0,8,7,6,5,4,3,2,1};
stargroup c(10, xc, yc);
con[14] = c; //Set(M);

prog_int16_t xd[] = {7,8,8,8,8,8};  //06 05 04 03 02
prog_int16_t yd[] = {0,8,7,6,5,4};
stargroup d(6, xd, yd);
con[15] = d; //Set(M);

prog_int16_t xs[] = {8,8};  
prog_int16_t ys[] = {3,2};
stargroup s(2, xs, ys);
con[16] = s; //Set(M);

prog_int16_t xt[] = {8,8,9,9};  
prog_int16_t yt[] = {1,0,8,7};
stargroup t(4, xt, yt);
con[17] = t; //Set(M);

prog_int16_t xv[] = {9,9,9,9};  
prog_int16_t yv[] = {6,5,4,3};
stargroup v(4, xv, yv);
con[18] = v; //Set(M);

prog_int16_t xw[] = {9,9,9,10,10,10};
prog_int16_t yw[] = {2,1,0,8,7,6};
stargroup w(6, xw, yw);
con[19] = w; //Set(M);

prog_int16_t xx[] = {10,10,10,10,10};  
prog_int16_t yx[] = {5,4,3,2,1};
stargroup x(5, xx, yx);
con[20] = x; //Set(M);

prog_int16_t xy[] = {10, 11};  
prog_int16_t yy[] = {0,8};
stargroup y(2, xy, yy);
con[21] = y; //Set(M);

prog_int16_t xz[] = {11,11,11};  
prog_int16_t yz[] = {7,6,5};
stargroup z(3, xz, yz);
con[22] = z; //Set(M);


prog_int16_t xzz[] = {11,11};  
prog_int16_t yzz[] = {4,3};
stargroup zz(2, xzz, yzz);
con[23] = zz;
}


void loop()                 // run over and over again
{
  
    Serial.print(" we are here ");
 // int count = 0; //used for timing
  bool up = true;  //up is used for twinkle direction.
  int lightup = 0; //used for which constellation is to be chosen.
 


 for (int k = 0; k < 10000; k++)
  {
  //If the frame counter is full, then it delays for scrollSpeed.
    if(frameCounter == 126)
    {
      delay(scrollSpeed);
      frameCounter=0;
    //  LedSign::Set(random(13), random(8), random(7));
     // count++;  
    }
  //at the end of the row, it advances Y to the next one
  if(xPosition == 13)yPosition++;
  //at the end of the row, it starts from the first LED in the next one
  if(xPosition > 13)xPosition=0;
   //at the end of the frame, it starts from the begining again
  if(yPosition > 8)yPosition=0;
  

  
   //twinkle the lights between 2 and 6 so they dont turn off completly
  if(greyscale > 6) up = false;
  if(greyscale < 2) up = true;
  if (up) greyscale++;
  if (!up) greyscale--;
  // here are some variations for twinkles, but they are commented out

   // greyscale = random(7); //random (comment out increment above)
   // if(greyscale > 7)greyscale= 0;  // original
   //  if(greyscale > 7)greyscale= 4;   //light twinkle

  //sends the current x, y, and color to the frame, one LED at a time
  LedSign::Set(xPosition, yPosition, greyscale);  //set normal light to twinkle
  LedSign::Set(random(13), random(8), random(2,6)); //set random light to random value.


  //the counters are at the end of the loop, which will advance everything
  //for the next frame
  xPosition++;
  frameCounter++;
  }
 
  for (int i = 0; i < cons; i++)
  {
    con[i].fadeOffAll();
  }
  
  delay(1000);
  
for (int i = 0; i < 5; i++)
{
  lightup = random(cons);
  con[lightup].fadeOn();
  delay(500);
  con[lightup].fadeOff();
  delay(500);
}
 
  
 // count = 0;
}




/////////////////////////////////////////








planet.h
Code:
/*
//  planet.h
//  
    This is the header file for the planatarium. This provides a class for each of the constelations. There is a global array set up in the main file that has as many constellations for that section. (EG oragne has 27)
 Individual constellations are defined as x and y pos in the setup loop. The main loop then just uses the global array of objects to trigger the events.//
//  Created by Rory McKay on 12/08/12.
// TODO: clean up privacy issues, take out any extra code.
*/

#ifndef _planet_h
#define _planet_h
#include "Charliplexing.h"
#include <avr/pgmspace.h>

class stargroup

{
public:
        //constructors
    stargroup();
    stargroup(int, prog_int16_t[], prog_int16_t[]);
    stargroup& operator= (const stargroup &source);
    
        //patterns
    void fadeOn();
    void on();
    void fadeOff();
    void fadeOffAll();
    void off();
    
        //variables
    prog_int16_t xPos[16];
    prog_int16_t yPos[16];
    int noOfStars;
    
};

void empty(int[], int[]);
#endif

Logged

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

planet.cpp
Code:
/*
//  planet.cpp
// 
//
//  Created by Rory McKay on 12/08/12.
//
*/
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <inttypes.h>
#include <math.h>
#include <avr/interrupt.h>
#include "Charliplexing.h"

#include "planet.h"

const int GLOBALDELAY = 100;


stargroup::stargroup()
{
    noOfStars = 0;
    xPos[16] = 0;
    yPos[16] =  0;
   
}

stargroup::stargroup(int x, prog_int16_t a[], prog_int16_t b[])
{
    noOfStars = x;
    for (int i = 0; i < noOfStars; i++)
    {
        xPos[i] = a[i];
        yPos[i] = b[i];
    }
    for (int i = noOfStars; i < 16; i++)
    {
        xPos[i] = 13;
        yPos[i] = 8;
    }
   
   
}



stargroup& stargroup::operator= (const stargroup &source)
{
    noOfStars = source.noOfStars;
    for (int i = 0; i < noOfStars; i++)
    {
        xPos[i] = source.xPos[i];
        yPos[i] = source.yPos[i];
    }
    for (int i = noOfStars; i < 16; i++)
    {
        xPos[i] = 13;
        yPos[i] = 8;
    }
    return *this;
}

void stargroup::fadeOn()
{
    for (int h = 0; h < 8; h++) //for all the different shades.
    {
        for (int i = 0; i < noOfStars; i++) //for each of the stars in the constilation.
        {
            LedSign::Set(xPos[i], yPos[i], h); //h is shade value
        }
        delay(GLOBALDELAY);
    }
   
}

void stargroup::on()
{
    for (int i = 0;i < noOfStars; i++) //for each of the stars in the constilation.
    {
        LedSign::Set(xPos[i], yPos[i], 7);
    }
    delay (GLOBALDELAY);
}

void stargroup::off()
{
    for (int i = 0;i < noOfStars; i++) //for each of the stars in the constilation.
    {
        LedSign::Set(xPos[i], yPos[i], 0);
    }
    delay (GLOBALDELAY);
}

void stargroup::fadeOff()
{
    for (int h = 8; h > 0; h--) //for all the different shades.
    {
        for (int i = 0; i < noOfStars; i++) //for each of the stars in the constilation.
        {
            LedSign::Set(xPos[i], yPos[i], h); //h is shade value
        }
        delay (GLOBALDELAY);
    }
   
}

void stargroup::fadeOffAll()
{
    for (int h = 8; h > 0; h--) //for all the different shades.
    {
        for (int i = 0; i < noOfStars; i++) //for each of the stars in the constilation.
        {
            LedSign::Set(xPos[i], yPos[i], h); //h is shade value
        }
        delay (1);
    }
   
}

void empty(int a[], int b[])
{
    for (int i = 0; i < 12; i++)
    {
        a[i] = 13;
        b[i] = 0;
    }
}
Logged

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

You can't write to PROGMEM at run time.
Make the private arrays RAM.

Edit: make them private too!(I just assumed they already were)
« Last Edit: August 18, 2012, 03:20:24 am by AWOL » 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.

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how and when do I write to progmem before runtime?
Thanks for your help  smiley
Logged

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

xPos  and yPos need to be in RAM, but the arrays that initialize them can be in progmem.
The compiler takes care of this for you when you declare them with the modifiers "prog_xxx".

And make them eight bit, not sixteen.
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.

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 3996
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, everything has to compile in PROGMEM. The sketch can't put values into flash. Note that there are only pgm_read_xxxx instructions, no pgm_write.

More, the pgm_read_xxxx instructions are only for the basic data types. But hey, isn't all the data you are using the same type?

What I would do is make 1 of each class object as a buffer for each and load data into the buffer as needed rather than have them all loaded when I can only work with 1 at a time anyway.  

Regardless of how you do it, that's what you have to work with if you want to use the relatively huge storage space in flash. Even if you were to put the data on an SD card (slower but gigs of space instead of kilobytes), it'd still make sense to work through a buffer.

OTOH you can get an Arduino or compatible with more RAM like a Mega2560 or Teensy++ or I think Crossroads has a design that uses a ATmega1284. All of those can use external RAM directly addressed by the MCU. I think it is Rugged Circuits that has up to 512k for the Mega2560 though that is in 64k banks you switch between. You could put a lot of sky up quicker that way.

Another sort of solution is to use a tablet/netbook/laptop/PC USB-connected to your Arduino as your data source. The Teensy's and I think the Leonardo do full speed USB as opposed to 115k serial to and from a USB chip (read: bottleneck) used by the UNO and Mega2560. LOL, a PC connected solution can support multiple Arduino-type machines through USB hub which would let you scale up for speed as each can probably draw some number of stars faster than human eyes can follow.

And that leaves me wondering how you place star-dots on the dome? I haven't been in a planetarium in over 40 years, the technology has probably changed just a bit.

Logged

Examples can be found in your IDE.

Pages: [1]   Go Up
Jump to: