Pages: [1]   Go Down
Author Topic: Compile Error; Need another set of eyes [solved]  (Read 237 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I'm trying to put together a 5-digit 7-segment display.  Unfortunately, I keep getting two compile errors that I can't track down the source of.  I was hoping another set of eyes could catch it, because I'm not finding any undefined variables or other weirdness that I'd expect to result in these errors.  Here're the errors:

"_7_seg_test_ver3:30: error: expected unqualified-id before 'return'
_7_seg_test_ver3:119: error: expected unqualified-id before 'return'"

I added inline comments to both lines so that they're easier to find below.    Thanks in advance, this is driving me nuts.

Code:
#define PIN_G 1
#define PIN_F 2
#define PIN_E 3
#define PIN_D 4
#define PIN_DP 5
#define PIN_C 6
#define PIN_B 7
#define PIN_A 8

#define DIGIT_0 9
#define DIGIT_1 10
#define DIGIT_2 11
#define DIGIT_3 12
#define DIGIT_4 13

#define FONT_1 B11111001
#define FONT_2 B01001100
#define FONT_3 B01101000
#define FONT_4 B00111001
#define FONT_5 B00101010
#define FONT_6 B00001011
#define FONT_7 B11111000
#define FONT_8 B00001000
#define FONT_9 B00111000
#define FONT_0 B10001000

void setup() {    

  pinMode(PIN_G, OUTPUT);
  digitalWrite(PIN_G, HIGH); // LINE 30
  pinMode(PIN_F, OUTPUT);
  digitalWrite(PIN_F, HIGH);
  pinMode(PIN_E, OUTPUT);
  digitalWrite(PIN_E, HIGH);
  pinMode(PIN_D, OUTPUT);
  digitalWrite(PIN_D, HIGH);
  pinMode(PIN_DP, OUTPUT);
  digitalWrite(PIN_DP, HIGH);
  pinMode(PIN_C, OUTPUT);
  digitalWrite(PIN_C, HIGH);
  pinMode(PIN_B, OUTPUT);
  digitalWrite(PIN_B, HIGH);
  pinMode(PIN_A, OUTPUT);
  digitalWrite(PIN_A, HIGH);
  
  pinMode(DIGIT_0, OUTPUT);
  digitalWrite(DIGIT_0, LOW);
  pinMode(DIGIT_1, OUTPUT);
  digitalWrite(DIGIT_1, LOW);
  pinMode(DIGIT_2, OUTPUT);
  digitalWrite(DIGIT_2, LOW);
  pinMode(DIGIT_3, OUTPUT);
  digitalWrite(DIGIT_3, LOW);
  pinMode(DIGIT_4, OUTPUT);
  digitalWrite(DIGIT_4, LOW);
}


byte segDisplay[10];
byte displayPosition = 0;
unsigned long currentValue = 0;
char decimalPosition = -1;

void tick(void)
{
  byte tmp;
  digitalWrite(PIN_A, HIGH);
  digitalWrite(PIN_B, HIGH);
  digitalWrite(PIN_C, HIGH);
  digitalWrite(PIN_D, HIGH);
  digitalWrite(PIN_E, HIGH);
  digitalWrite(PIN_G, HIGH);
  digitalWrite(PIN_DP, HIGH);
  digitalWrite(DIGIT_0, LOW);
  digitalWrite(DIGIT_1, LOW);
  digitalWrite(DIGIT_2, LOW);
  digitalWrite(DIGIT_3, LOW);
  digitalWrite(DIGIT_4, LOW);
  
  if(displayPosition > 4) displayPosition = 0;  
  
  tmp = segDisplay[displayPosition];
  
  if(bitRead(tmp, 7) == 0) digitalWrite(PIN_G, LOW);
  if(bitRead(tmp, 6) == 0) digitalWrite(PIN_F, LOW);
  if(bitRead(tmp, 5) == 0) digitalWrite(PIN_E, LOW);
  if(bitRead(tmp, 4) == 0) digitalWrite(PIN_D, LOW);
  if(bitRead(tmp, 3) == 0) digitalWrite(PIN_DP, LOW);
  if(bitRead(tmp, 2) == 0) digitalWrite(PIN_C, LOW);
  if(bitRead(tmp, 1) == 0) digitalWrite(PIN_B, LOW);
  if(bitRead(tmp, 0) == 0) digitalWrite(PIN_A, LOW);
  
  
  switch(displayPosition)
  {
    case 0:
      digitalWrite(DIGIT_0, HIGH);
      displayPosition++;
      break;
    case 1:
      digitalWrite(DIGIT_1, HIGH);
      displayPosition++;
      break;
    case 2:
      digitalWrite(DIGIT_2, HIGH);
      displayPosition++;
      break;
    case 3:
      digitalWrite(DIGIT_3, HIGH);
      displayPosition++;
      break;
    case 4:
      digitalWrite(DIGIT_4, HIGH);
      displayPosition++;
      break;
  };
}

return byte setDigit(int val) // LINE 119
{
  displayPosition = 0;
  byte tmp = 0;
  switch(val)
  {
    case 0:
      tmp = FONT_0;
      break;
    case 1:
      tmp = FONT_1;
      break;
    case 2:
      tmp = FONT_2;
      break;
    case 3:
      tmp = FONT_3;
      break;
    case 4:
      tmp = FONT_4;
      break;
    case 5:
      tmp = FONT_5;
      break;
    case 6:
      tmp = FONT_6;
      break;
    case 7:
      tmp = FONT_7;
      break;
    case 8:
      tmp = FONT_8;
      break;
    case 9:
      tmp = FONT_9;
      break;
    default:
      tmp = 0;
  };
  return tmp;
}

void setValue(unsigned long val)
{
  currentValue = val;
  for(char count = 9; count >= 0; count--)
  {
    segDisplay[count] = setDigit(val%10);
    val = val / 10;
  }
}


void loop() {
  tick();
  delay(10);
}
« Last Edit: January 02, 2013, 02:11:15 am by Nick Gammon » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 209
Posts: 13027
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Change...

Code:
return byte setDigit(int val) // LINE 119
{

...to...

Code:
byte setDigit(int val) // LINE 119
{
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, duh.  I knew it had to be something stupid like that, but I wasn't seeing it.

Thank you very much!
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4334
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know that the cause of the error has been found and fixed but, as a matter of interest, why are there semi-colons at the end of lines 116 and 157 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I just forgot to remove them after an edit.  smiley
Logged

Pages: [1]   Go Up
Jump to: