did you forget the '&' ?

When trying to insert leading zero’s into a matrix clock display the following error message is displayed, looking in arduino reference the only reference I could find was Bitwise AND (&), could someone explain the meaning of the error message.

Matrix_Clock_Test1.ino: In function 'void loop()':
Matrix_Clock_Test1:253: error: invalid use of member (did you forget the '&' ?)
Matrix_Clock_Test1:253: error: expected primary-expression before '}' token
Matrix_Clock_Test1:253: error: expected `;' before '}' token
Matrix_Clock_Test1.ino: At global scope:
Matrix_Clock_Test1:254: error: expected constructor, destructor, or type conversion before '.' token
Matrix_Clock_Test1:255: error: expected constructor, destructor, or type conversion before '.' token
Matrix_Clock_Test1:256: error: expected constructor, destructor, or type conversion before '.' token
Matrix_Clock_Test1:257: error: expected constructor, destructor, or type conversion before '.' token
Matrix_Clock_Test1:259: error: expected unqualified-id before 'for'
Matrix_Clock_Test1:259: error: expected constructor, destructor, or type conversion before '<' token
Matrix_Clock_Test1:259: error: expected constructor, destructor, or type conversion before '++' token
Matrix_Clock_Test1:267: error: expected declaration before '}' token

Program of matrix clock

#include <SPI.h>
#include <Wire.h>
#include "RTClib.h"
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>


/* Max7219 settings */
int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 5;
int numberOfVerticalDisplays = 1;


Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
RTC_DS1307 rtc;

unsigned char a;
unsigned char j;

/*Port Definitions*/
int Max7219_pinCLK = 13;
int Max7219_pinCS = 10;
int Max7219_pinDIN = 11;



unsigned char disp1[38][8]={
  {
    0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C  }
  ,//0
  {
    0x10,0x18,0x14,0x10,0x10,0x10,0x10,0x10  }
  ,//1
  {
    0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E  }
  ,//2
  {
    0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0  }
  ,//3
  {
    0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8  }
  ,//4
  {
    0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0  }
  ,//5
  {
    0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0  }
  ,//6
  {
    0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8  }
  ,//7
  {
    0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E  }
  ,//8
  {
    0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E  }
  ,//9
  {
    0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22  }
  ,//A
  {
    0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0  }
  ,//B
  {
    0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0  }
  ,//C
  {
    0x7C,0x42,0x42,0x42,0x42,0x42,0x7C,0x0  }
  ,//D
  {
    0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C  }
  ,//E
  {
    0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40  }
  ,//F
  {
    0x3C,0x40,0x40,0x40,0x40,0x44,0x44,0x3C  }
  ,//G
  {
    0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44  }
  ,//H
  {
    0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C  }
  ,//I
  {
    0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30  }
  ,//J
  {
    0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24  }
  ,//K
  {
    0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C  }
  ,//L
  {
    0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81  }
  ,//M
  {
    0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0  }
  ,//N
  {
    0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C  }
  ,//O
  {
    0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20  }
  ,//P
  {
    0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D  }
  ,//Q
  {
    0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21  }
  ,//R
  {
    0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C  }
  ,//S
  {
    0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8  }
  ,//T
  {
    0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C  }
  ,//U
  {
    0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18  }
  ,//V
  {
    0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0  }
  ,//W
  {
    0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41  }
  ,//X
  {
    0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8  }
  ,//Y
  {
    0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F  }
  ,//Z
};

/* Set up Scrolling Time and Date settings */
String tape ="99:99:99  99/99/9999";
int tape_length = 22;
int wait = 50; // In milliseconds

int spacer = 1;
int width = 5 + spacer; // The font width is 5 pixels
int i = 0;


/* Set up display of Time only */
void Write_Max7219_byte(unsigned char DATA) 
{   
  unsigned char a;
  digitalWrite(Max7219_pinCS,LOW);		
  for(a=8;a>=1;a--)
  {		  
    digitalWrite(Max7219_pinCLK,LOW);
    digitalWrite(Max7219_pinDIN,DATA&0x80);// Extracting a bit data
    DATA = DATA<<1;
    digitalWrite(Max7219_pinCLK,HIGH);
  }                                 
}


void Write_Max7219(unsigned char address,unsigned char dat)
{
  digitalWrite(Max7219_pinCS,LOW);
  Write_Max7219_byte(address);           //address,code of LED
  Write_Max7219_byte(dat);               //data,figure on LED 
  digitalWrite(Max7219_pinCS,HIGH);
}

void Init_MAX7219(void)
{
  Write_Max7219(0x09, 0x00);       //decoding :BCD
  Write_Max7219(0x0a, 0x03);       //brightness 
  Write_Max7219(0x0b, 0x07);       //scanlimit;8 LEDs
  Write_Max7219(0x0c, 0x01);       //power-down mode:0,normal mode:1
  Write_Max7219(0x0f, 0x00);       //test display:1;EOT,display:0
}

void setup()
{

  /*Init Max7219*/
  pinMode(Max7219_pinCLK,OUTPUT);
  pinMode(Max7219_pinCS,OUTPUT);
  pinMode(Max7219_pinDIN,OUTPUT);
  delay(50);
  Init_MAX7219();

  /* Check if RTC running and set intensity of display */
  matrix.setIntensity(0); // Use a value between 0 and 15 for brightness
#ifdef AVR
  Wire.begin();
#else
  Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
  rtc.begin();

  if (! rtc.isrunning()) {
    matrix.print("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop() {

  DateTime now = rtc.now();


  /* Scrolling to show the date and time */

  tape[0] = '0' + ((now.hour())/10);  // I assume you want the time first
  tape[1] = '0' + ((now.hour())%10);
  tape[3] = '0' + ((now.minute())/10);
  tape[4] = '0' + ((now.minute())%10);
  tape[6] = '0' + ((now.second())/10);
  tape[7] = '0' + ((now.second())%10);

  tape[10] = '0' + ((now.day())/10); 
  tape[11] = '0' + ((now.day())%10);
  tape[13] = '0' + ((now.month())/10);
  tape[14] = '0' + ((now.month())%10);
  tape[16] = '0' + ((now.year())/1000);
  tape[17] = '0' + (((now.year())/100)%10);
  tape[18] = '0' + (((now.year())/10)%10);
  tape[19] = '0' + ((now.year())%10);

  for ( int i = 0 ; i < width * tape_length + matrix.width() - 1 - spacer; i++ ) {

    matrix.fillScreen(LOW);

    int letter = i / width;
    int x = (matrix.width() - 1) - i % width;
    int y = (matrix.height() - 8) / 2; // center the text vertically
    while ( x + width - spacer >= 0 && letter >= 0 ) {
      if ( letter < tape_length ) {

        matrix.drawChar(x, y, tape[letter], HIGH, LOW, 1);
      }

      letter--;
      x -= width;
    }
    matrix.write(); // Send bitmap to display

    delay(wait);    
  }
  /* Print time only */

  matrix.setPosition(0,0,0);
  matrix.print(now.hour(),DEC);
  if (now.hour >10)}
  matrix.print(now.hour();
  matrix.print(0);
  matrix.print(':');
  matrix.print(now.minute(),DEC);
  matrix.write();

  for(j=0;j<38;j++)
  {
    for(a=1;a<9;a++)
      Write_Max7219(a,disp1[j][a-1]);
    delay(500);

  }

}
if (now.hour >10)}

?

That is what has been put in place

/* Print time only */

  matrix.setPosition(0,0,0);
  matrix.print(now.hour(),DEC);
  if (now.hour >10)}
  matrix.print(0);
  matrix.print(now.hour();
   matrix.print(':');
  matrix.print(now.minute(),DEC);
  matrix.write();

  for(j=0;j<38;j++)
  {
    for(a=1;a<9;a++)
      Write_Max7219(a,disp1[j][a-1]);
    delay(500);

  }

JQuinn: That is what has been put in place

What does that mean?

The clock display only shows 1:2 when it needs to show 01:02, code was to insert a leading zero when hours and minutes show 1 to 9, only the code for the hours has been inserted for program testing and error correcting and the above error is what comes up and I do not know why!

I'll try one more time.

if (now.hour >10)}

Why is there a closing brace at the end of that line?

Also, isn't 'hour' a function? Look on the line above, it uses:

now.hour()

Yet you have used:

now.hour

I am sure the & they are referring to is not the bitwise and, but the “take the address of” operator.

What happens in this expression:

  if (now.hour >10)}

if you have the brace facing the "normal" way?

AWOL

code taken from "How to display time for your arduino clock project - for dummies.

Tom Carpenter

just ran code with “now.hour()” and it comes up with errors

Matrix_Clock_Test1.ino: In function 'void loop()':
Matrix_Clock_Test1:181: error: expected primary-expression before ')' token
Matrix_Clock_Test1:181: error: expected `;' before ')' token
Matrix_Clock_Test1.ino: At global scope:
Matrix_Clock_Test1:182: error: expected constructor, destructor, or type conversion before '.' token
Matrix_Clock_Test1:183: error: expected constructor, destructor, or type conversion before '.' token
Matrix_Clock_Test1:184: error: expected constructor, destructor, or type conversion before '.' token
Matrix_Clock_Test1:185: error: expected constructor, destructor, or type conversion before '.' token
Matrix_Clock_Test1:187: error: expected unqualified-id before 'for'
Matrix_Clock_Test1:187: error: expected constructor, destructor, or type conversion before '<' token
Matrix_Clock_Test1:187: error: expected constructor, destructor, or type conversion before '++' token
Matrix_Clock_Test1:195: error: expected declaration before '}' token

Econjack

it was supposed to insert a leading zero when hours were between 1 and 9.

just ran code with "now.hour()" and it comes up with errors

You didn't "run" the code (whatever it looks like now), you tried and failed to compile it.

Please post your code.

Replace this

if (now.hour >10)}
  matrix.print(0);
  matrix.print(now.hour();

By this (and study the changes)

if ( now.hour() < 10 )
{
  matrix.print(0);
}
matrix.print( now.hour() );

guix

Inserted you code compiles ok but now display 202:26 where it should show 02:26.

AWOL

This is the original code without any extra code added, compiles and runs but only shows 2:26 where it is required to show 02:26.

#include <SPI.h>
#include <Wire.h>
#include "RTClib.h"
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>


/* Max7219 settings */
int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 5;
int numberOfVerticalDisplays = 1;


Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
RTC_DS1307 rtc;

unsigned char a;
 unsigned char j;
 
/*Port Definitions*/
int Max7219_pinCLK = 13;
int Max7219_pinCS = 10;
int Max7219_pinDIN = 11;
 

 
unsigned char disp1[38][8]={
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//0
{0x10,0x18,0x14,0x10,0x10,0x10,0x10,0x10},//1
{0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2
{0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0},//3
{0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8},//4
{0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0},//5
{0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0},//6
{0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8},//7
{0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E},//8
{0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E},//9
{0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22},//A
{0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0},//B
{0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0},//C
{0x7C,0x42,0x42,0x42,0x42,0x42,0x7C,0x0},//D
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C},//E
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40},//F
{0x3C,0x40,0x40,0x40,0x40,0x44,0x44,0x3C},//G
{0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44},//H
{0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C},//I
{0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30},//J
{0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24},//K
{0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C},//L
{0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81},//M
{0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0},//N
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//O
{0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20},//P
{0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D},//Q
{0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21},//R
{0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C},//S
{0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8},//T
{0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C},//U
{0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18},//V
{0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0},//W
{0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41},//X
{0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8},//Y
{0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F},//Z
};

/* Set up Scrolling Time and Date settings */
String tape ="99:99:99  99/99/9999";
int tape_length = 22;
int wait = 50; // In milliseconds

int spacer = 1;
int width = 5 + spacer; // The font width is 5 pixels
int i = 0;


/* Set up display of Time only */
void Write_Max7219_byte(unsigned char DATA) 
{   
            unsigned char a;
	    digitalWrite(Max7219_pinCS,LOW);		
	    for(a=8;a>=1;a--)
          {		  
             digitalWrite(Max7219_pinCLK,LOW);
             digitalWrite(Max7219_pinDIN,DATA&0x80);// Extracting a bit data
             DATA = DATA<<1;
             digitalWrite(Max7219_pinCLK,HIGH);
           }                                 
}
 
 
void Write_Max7219(unsigned char address,unsigned char dat)
{
        digitalWrite(Max7219_pinCS,LOW);
        Write_Max7219_byte(address);           //address,code of LED
        Write_Max7219_byte(dat);               //data,figure on LED 
        digitalWrite(Max7219_pinCS,HIGH);
}
 
void Init_MAX7219(void)
{
 Write_Max7219(0x09, 0x00);       //decoding :BCD
 Write_Max7219(0x0a, 0x03);       //brightness 
 Write_Max7219(0x0b, 0x07);       //scanlimit;8 LEDs
 Write_Max7219(0x0c, 0x01);       //power-down mode:0,normal mode:1
 Write_Max7219(0x0f, 0x00);       //test display:1;EOT,display:0
}

void setup()
{
  
/*Init Max7219*/  
  pinMode(Max7219_pinCLK,OUTPUT);
  pinMode(Max7219_pinCS,OUTPUT);
  pinMode(Max7219_pinDIN,OUTPUT);
  delay(50);
  Init_MAX7219();
  
/* Check if RTC running and set intensity of display */  
 matrix.setIntensity(0); // Use a value between 0 and 15 for brightness
  #ifdef AVR
  Wire.begin();
#else
  Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
  rtc.begin();
  
 if (! rtc.isrunning()) {
    matrix.print("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop() {

  DateTime now = rtc.now();
  
  
  /* Scrolling to show the date and time */
  
  tape[0] = '0' + ((now.hour())/10);  // I assume you want the time first
  tape[1] = '0' + ((now.hour())%10);
  tape[3] = '0' + ((now.minute())/10);
  tape[4] = '0' + ((now.minute())%10);
  tape[6] = '0' + ((now.second())/10);
  tape[7] = '0' + ((now.second())%10);
  
  tape[10] = '0' + ((now.day())/10); 
  tape[11] = '0' + ((now.day())%10);
  tape[13] = '0' + ((now.month())/10);
  tape[14] = '0' + ((now.month())%10);
  tape[16] = '0' + ((now.year())/1000);
  tape[17] = '0' + (((now.year())/100)%10);
  tape[18] = '0' + (((now.year())/10)%10);
  tape[19] = '0' + ((now.year())%10);
  
  for ( int i = 0 ; i < width * tape_length + matrix.width() - 1 - spacer; i++ ) {

    matrix.fillScreen(LOW);

    int letter = i / width;
    int x = (matrix.width() - 1) - i % width;
    int y = (matrix.height() - 8) / 2; // center the text vertically
    while ( x + width - spacer >= 0 && letter >= 0 ) {
      if ( letter < tape_length ) {
        
        matrix.drawChar(x, y, tape[letter], HIGH, LOW, 1);
      }
      
      letter--;
      x -= width;
         }
     matrix.write(); // Send bitmap to display
        
    delay(wait);    
}
/* Print time only */

  matrix.setPosition(0,0,0);
   matrix.print(now.hour(),DEC);
    matrix.print(':');
    matrix.print(now.minute(),DEC);
   matrix.write();
  
   for(j=0;j<38;j++)
  {
   for(a=1;a<9;a++)
    Write_Max7219(a,disp1[j][a-1]);
   delay(500);
  
}

}

JQuinn: guix

Inserted you code compiles ok but now display 202:26 where it should show 02:26.

Put a little effort in trying to understand the code that you use...

  matrix.setPosition(0,0,0);
  if (now.hour() < 10)
  {
    matrix.print('0');
  }
  matrix.print(now.hour());
  matrix.print(':');
  matrix.print(now.minute());
  matrix.write();

(You may have to do the same for minutes)

guix and AWOL

Program works and shows 03:01. Was the problem that I used 'DEC' instead of leaving it off. Now the project can be completed. Many thanks to you both for your help, the problem had me scratching my head for a while before I came onto the forum for help.

You could have used sprintf too ;)

char timeStr[6]; // enough space for "XX:XX\0"
sprintf( timeStr, "%02d:%02d", now.hour(), now.minute() );
matrix.print( timeStr );

Your actual code is more efficient, using sprintf just simplify things, at the cost of performance and memory.

Was the problem that I used 'DEC' instead of leaving it off.

No. The problem is that you didn't spend enough time to learn how the code works. You need to walk yourself through the answers that have been given to you until you understand what they are doing. Until you make that effort, you will not understand the solutions being presented, which means you are destined to make the same mistakes over and over again.

JQuinn: guix and AWOL

Program works and shows 03:01. Was the problem that I used 'DEC' instead of leaving it off. Now the project can be completed. Many thanks to you both for your help, the problem had me scratching my head for a while before I came onto the forum for help.

If you omit the base (DEC in this case but could be BIN or HEX) then the compiler supplies the default base . . . which is DEC. So, despite what you think, that wasn't your problem.

One last question, having my background in hardware not software puts me at a disadvantage when writing programs, but you learn from your mistakes. I have also found that when the program is being powered externally only the scrolling part is working, could this be because removing the USB of the PC you lose the serial port or is it a mistake in the way the writing of the program has been done.