error: expected initializer before '  '

byte CONST LED_MAP[10] =
(0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67); //LED HEX CODES

pinMode (8, OUTPUT) //COM1
pinMode (9, OUTPUT) //COM2
pinMode (1, OUTPUT) //SEG A
pinMode (2, OUTPUT) //SEG B
pinMode (3, OUTPUT) //SEG C
pinMode (4, OUTPUT) //SEG D
pinMode (5, OUTPUT) //SEG E
pinMode (6, OUTPUT) //SEG F
pinMode (7, OUTPUT) //SEG G

void display_number ( int n ) {
PORTD = (LED_MAP[n/10]);
PORTB |= B0001;
delay_ms(2);
PORTB |= B0000;
PORTD = (LED_MAP[n%10]);
PORTB |= B0010;
delay_ms(2);
PORTB |= B0000;
}

void setup() {
}

So I'm trying to get my dual 7 seg display working with my duemilanove. I'm still getting used to the Arduino syntax and am having a little trouble with this error:

error: expected initializer before 'LED_MAP'

and

error: expected constructor, destructor, or type conversion before '.' token In function 'void display_number(int)':

I just want it to compile. writing a little counter program will be easy enough if I can get past this.
Thanks! :wink:

//const datatype not datatype CONST
const byte LED_MAP[10] = 
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};//USE {} not () on array declaration //LED HEX CODES


void display_number ( int n ) {
 PORTD = (LED_MAP[n/10]);
 PORTB |= B0001;
 delay_ms(2);
 PORTB |= B0000;
 PORTD = (LED_MAP[n%10]);
 PORTB |= B0010;
 delay_ms(2);
 PORTB |= B0000;
}
 
void setup()   {
  //call pinMode inside setup, remember ;
  pinMode (8, OUTPUT);  //COM1
  pinMode (9, OUTPUT);  //COM2
  pinMode (1, OUTPUT);  //SEG A
  pinMode (2, OUTPUT);  //SEG B
  pinMode (3, OUTPUT);  //SEG C 
  pinMode (4, OUTPUT);  //SEG D
  pinMode (5, OUTPUT);  //SEG E
  pinMode (6, OUTPUT);  //SEG F
  pinMode (7, OUTPUT); //SEG G
}  

void loop(){/*implement*/}

Hope this helps.
Completly untested, but I think it compiles. :slight_smile:

ok,
so now it looks like this

const byte LED_MAP[10] =
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}; //LED HEX CODES

void display_number ( int n ) {
PORTD = (LED_MAP[n/10]);
PORTB |= B0001;
delay(2);
PORTB |= B0000;
PORTD = (LED_MAP[n%10]);
PORTB |= B0010;
delay(2);
PORTB |= B0000;
}

void setup() {

pinMode (8, OUTPUT); //COM1
pinMode (9, OUTPUT); //COM2
pinMode (1, OUTPUT); //SEG A
pinMode (2, OUTPUT); //SEG B
pinMode (3, OUTPUT); //SEG C
pinMode (4, OUTPUT); //SEG D
pinMode (5, OUTPUT); //SEG E
pinMode (6, OUTPUT); //SEG F
pinMode (7, OUTPUT); //SEG G
}

o: In function main': C:\Users\KAPTAI~1\AppData\Local\Temp\build50242.tmp/Temporary_9304_2162.cpp:39: undefined reference to loop'

Couldn't determine program size: C:\Users\Kaptain K\Arduino\arduino-0016\hardware/tools/avr/bin/avr-size: 'C:\Users\KAPTAI~1\AppData\Local\Temp\build50242.tmp\sketch_090805a.hex': No such file

Hmmmm.

Perhaps I'm reaching here, but maybe you need to add the loop routine?

yeah I think you're right.

const byte LED_MAP[10] =
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}; //LED HEX CODES

void display_number ( int n ) {
PORTD = (LED_MAP[n/10]);
PORTB |= B0001;
delay(2);
PORTB |= B0000;
PORTD = (LED_MAP[n%10]);
PORTB |= B0010;
delay(2);
PORTB |= B0000;
}

void setup() {

pinMode (8, OUTPUT); //COM1
pinMode (9, OUTPUT); //COM2
pinMode (1, OUTPUT); //SEG A
pinMode (2, OUTPUT); //SEG B
pinMode (3, OUTPUT); //SEG C
pinMode (4, OUTPUT); //SEG D
pinMode (5, OUTPUT); //SEG E
pinMode (6, OUTPUT); //SEG F
pinMode (7, OUTPUT); //SEG G

}
void loop(){
int count=1,i;
for(i=0;i<=200;i++){
display_number(count);
count = (count==99) ? 1: count+1;
}
}

Compiles great!
but I can't get any output!
Completely blank. wired correctly. i am sure of that.

PS. thanks for your quick help guys!

Those delay(2) statements are going to give you a 2 millisecond delay, is that what you intend? I suspect that you want 2 second delays there, in which case you would want a delay(2000).

It is a good idea to comment your code with what you intend it to do, and why. Often this makes finding flaws faster, particularly when you call in a second set of eyes (or come back to it yourself at a later date).

I shall comment today when I get home. Working right now :slight_smile:

the display_number function is intended to drive a dual 7 seg display.
I will also post the part number for that when I get home.
The function will light one digit, then the other and back and forth with the 2ms delay blinking quickly gives the illusion they are on at all times.
I''m trying to create a variation on the syntax I used in a college lab, however we used a microchip pic.
this lab shows how you can drive 2 leds with 9 wires instead of 14(a1,a2,b1,b2,c1,c2,d1,d2,e1,e2,f1,f2,g1,g2, com1 and com2) the segments (ie. a1 and a2) are connected to the same output pin and com1/2 being high/low decides which digit is on at any given time.
The hex map decides which segments are on converting the hex to a binary and driving the outputs.

If you remove the loop contents and just display a single number with no bank switching or delays do the correct segments light?

void loop(){
digitalWrite(8, HIGH);
digitalWrite(1, HIGH);
}

if I use that instead of the loop it will light one segment. Maybe something wrong with my display number function?

That would be what I would evaluate next. Decompose display_number() into it's basic parts and test each operation individually. Something like this:

#define D_NONE B0000
#define D_ZERO B0001
#define D_ONE B0010

const byte LED_MAP[10] =
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}; //LED HEX CODES

void enable_digit(byte b){
 PORTB |= b;
}

void display_map(byte n){
 PORTD = (LED_MAP[n]);
}

void display_number(byte n, int duration){
  int start = millis();
  do{
    enable_digit(D_NONE);
    display_map(n/10);
    enable_digit(D_ZERO);
    delay(2);
    enable_digit(D_NONE);
    display_map(n%10);
    enable_digit(D_ONE);
    delay(2);
  }while( millis() < (start+duration) );
}

void setup(){
  for( byte i=0; i<9; i++ )
    pinMode (i, OUTPUT); 
}  

void loop(){
  // Test digit zero and then one with the map for '3'
  display_map( 3 );
  enable_digit( D_ZERO );
  delay(1000);
  enable_digit( D_ONE );
  delay(1000);
 
  // display each of 0-99 for half a second each
  while(1)
    for (byte i=0; i<99; i++)
      display_number(i, 500);
}

I'm not suggesting that this is particularly efficient code, it's just broken down into distinct functional bits so that it's easy to test each piece separately.