Pages: [1]   Go Down
Author Topic: help my program please  (Read 715 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is my program error

Code:
  saveInterval = saveInt(); //call saveInt sub-function and return value
  lcdInterval = lcdInt();   //call lcdInt sub-function and return value

and
Code:
int saveInt() {
  int buttonValue1;
  int buttonValue2;
  int buttonState;
  int minutes;

  lcd.clear();
  lcd.print("Choose save interval");
  delay(500);
  lcd.setCursor(0,1);
  lcd.print(saveInterval);
  lcd.setCursor(3,1);
  lcd.print("seconds");
  buttonState = digitalRead(button1);
 
 
    buttonValue1 = digitalRead(button1);
    delay(10);
    buttonValue2 = digitalRead(button1);
    if (buttonValue1 == buttonValue2) {
      if (buttonValue1 != buttonState) {
        if (buttonValue1 == LOW) {
          if (saveInterval >= 5 && saveInterval < 20) {
            saveInterval = saveInterval + 5; //set value to 5, 10, 15 or 20 seconds
          } else if(saveInterval >= 20 && saveInterval < 30) {
            saveInterval = saveInterval + 10; //set value to 30 seconds
          } else if(saveInterval >= 30 && saveInterval < 60) {
            saveInterval = saveInterval + 30; //set value to 60 seconds
          } else if(saveInterval >= 60 && saveInterval < 120) {
            saveInterval = saveInterval + 60; //set value to 120 seconds
          } else if(saveInterval >= 120 && saveInterval < 300) {
            saveInterval = saveInterval + 180; //set value to 5 minutes (300 seconds)
          } else if(saveInterval >= 300 && saveInterval < 600) {
            saveInterval = saveInterval + 300; //set value to 10 minutes (600 seconds)
          } else if(saveInterval >= 600) {
            saveInterval = 5; //circle back to 5 seconds after reaching 600 second option
          }
          //Show the user the current saveInterval value before the while loop starts over
          //again and checks for new button presses
          lcd.setCursor(0,1);
          lcd.print("   ");
          if (saveInterval <= 60) {
            lcd.setCursor(0,1);
            lcd.print(saveInterval);
            lcd.setCursor(3,1);
            lcd.print("seconds");
          } else if(saveInterval > 60) {
            minutes = saveInterval / 60;
            lcd.setCursor(0,1);
            lcd.print(minutes);
            lcd.setCursor(3,1);
            lcd.print("minutes");
          }
   
        }
      }
      buttonState = buttonValue1; //update buttonState so that only changes
                                  //in button status are registered
    }

 }//while loop has expired, show user that their choice is being stored
  lcd.setCursor(0,3);
  lcd.print("Storing");
  delay(400);
  for (int i = 0; i <= 2; i++) {
    lcd.print(".");
    delay(350);
  }
  return saveInterval;
} //end of saveInt sub-routine

and this is a messagge error

Code:
sketch_jul03c.cpp: In function 'void setup()':
sketch_jul03c:156: error: 'saveInt' was not declared in this scope
sketch_jul03c.cpp: In function 'void loop()':
sketch_jul03c:247: error: a function-definition is not allowed here before '{' token
sketch_jul03c:428: error: expected `}' at end of input
Logged

Offline Offline
God Member
*****
Karma: 19
Posts: 781
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please post the whole code.

The error looks like you may have a function declared inside another function.  Or maybe you have some curly braces mixed up.
Logged

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

this is my whole code.

Code:
#include <SD.h>
#include <LiquidCrystal.h>

int CS_pin = 53;

volatile long lastSave = 0;
volatile long lcdTimeOut = 0;
volatile int saveInterval = 10;
volatile int lcdInterval= 60;
const int reps = 9;

LiquidCrystal lcd(8,3,4,5,6,7);

 
#define muxA0 15
#define muxA1 16
#define muxA2 17
#define tempPin 0
#define lcdLight 9
#define button1 2                  
int button1INT = 0;
                    

#define aref_voltage 1.1


const int chs = 8;
const int numReadings = 10;
long tempInArray[numReadings][chs];
int index = 0;
long total[chs];
float averages[chs];

void error(char *str)
{
  lcd.clear();
  lcd.home();
  lcd.print("error: ");
  lcd.print(str);
  while(1);
}

void setup(void)
{
 
  analogReference(INTERNAL1V1);
                      
  pinMode(muxA2, OUTPUT);
  pinMode(muxA1, OUTPUT);
  pinMode(muxA0, OUTPUT);
  pinMode(button1, INPUT);
  digitalWrite(lcdLight, HIGH);
  lcd.begin(20,4);  
  lcd.setCursor(0,0);
  lcd.print("Tugas Akhir");
  lcd.setCursor(0,1);
  lcd.print("Miniatur Hujan Salju");
  delay (5000);
  lcd.clear();
  
  lcd.setCursor(0,0);
  lcd.print ("Oleh: ");
  lcd.setCursor(0,1);
  lcd.print ("Mochamad Rikki Firmansyah");
  lcd.setCursor(0,2);
  lcd.print ("dan");
  lcd.setCursor(0,3);
  lcd.print ("Ichsan T Primanizar");
  delay (5000);
  lcd.clear();

  //initialize the SD card
  if (!SD.begin(CS_pin))
    {
      lcd.setCursor(0,0);
      lcd.println ("Card Failure ");
      delay (3000);
      lcd.clear();
      return;
    }
      lcd.println ("Card Ready");
      delay (3000);
      lcd.clear();
      
  
  File commandFile = SD.open ("COMMAND.txt");
  if (commandFile)
  {
    lcd.setCursor(0,0);
    lcd.println ("Membaca File");
    delay (3000);
    lcd.clear();
    while (commandFile.available());
  }
  else
  {
    lcd.println ("File Tdk Trsedia");
    delay (3000);
    lcd.clear();
  }
  
  
  File logFile = SD.open ("LOG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.println (", , , , , , , ,");
    String header = "Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7, Ch8";
    logFile.println (header);
    logFile.close();
  }
  else
  {
    lcd.setCursor (0,0);
    lcd.print  ("data failed");
    delay (2000);
    lcd.clear();
  }


  saveInterval = saveInt(); //call saveInt sub-function and return value
  lcdInterval = lcdInt();   //call lcdInt sub-function and return value


  for (int channel = 0; channel < chs; channel++) {
    for (int i = 0; i < numReadings; i++) {
      tempInArray[i][channel] = 0; //initialize all values to 0
    }
  }
}
 


void loop(void)
{
  
  for (int channel = 0; channel < chs; channel++) {
    total[channel] = total[channel] - tempInArray[index][channel];
  }
  

    for (int channel = 0; channel < chs; channel++) {
    
      digitalWrite(muxA0, (channel & 1));
      digitalWrite(muxA1, (channel & 2)>>1);
      digitalWrite(muxA2, (channel & 4)>>2);  
      delay(5);
      
    
      analogRead(tempPin);
      delay(20);
      tempInArray[index][channel] = analogRead(tempPin);    
        
  }
  for (int channel = 0; channel < chs; channel++) {
    total[channel] = total[channel] + tempInArray[index][channel];
    averages[channel] = total[channel] / numReadings;
    averages[channel] = averages[channel] * aref_voltage / 1024;
    averages[channel] = averages[channel] * 100;
  }
    
  index = index++;
  if (index >= numReadings) {
    index = 0;
  }

  delay(500);  
              
  lcd.home();
  int row = 0;
  for (int i = 0; i <=6; i = i + 2) {
    lcd.setCursor(0,row);
    lcd.print("Ch");
    lcd.print(i+1);
    lcd.print(":");
  lcdPrintDouble(averages[i],1);
    lcd.setCursor(10,row);
    lcd.print("Ch");
    lcd.print(i+2);
    lcd.print(":");  
   lcdPrintDouble(averages[i+1],1);  
    row++; //increment row counter
  }

int saveInt() {
  int buttonValue1;
  int buttonValue2;
  int buttonState;
  int minutes;

  lcd.clear();
  lcd.print("Choose save interval");
  delay(500);
  lcd.setCursor(0,1);
  lcd.print(saveInterval);
  lcd.setCursor(3,1);
  lcd.print("seconds");
  buttonState = digitalRead(button1);
  
  
    buttonValue1 = digitalRead(button1);
    delay(10);
    buttonValue2 = digitalRead(button1);
    if (buttonValue1 == buttonValue2) {
      if (buttonValue1 != buttonState) {
        if (buttonValue1 == LOW) {
          if (saveInterval >= 5 && saveInterval < 20) {
            saveInterval = saveInterval + 5; //set value to 5, 10, 15 or 20 seconds
          } else if(saveInterval >= 20 && saveInterval < 30) {
            saveInterval = saveInterval + 10; //set value to 30 seconds
          } else if(saveInterval >= 30 && saveInterval < 60) {
            saveInterval = saveInterval + 30; //set value to 60 seconds
          } else if(saveInterval >= 60 && saveInterval < 120) {
            saveInterval = saveInterval + 60; //set value to 120 seconds
          } else if(saveInterval >= 120 && saveInterval < 300) {
            saveInterval = saveInterval + 180; //set value to 5 minutes (300 seconds)
          } else if(saveInterval >= 300 && saveInterval < 600) {
            saveInterval = saveInterval + 300; //set value to 10 minutes (600 seconds)
          } else if(saveInterval >= 600) {
            saveInterval = 5;
          }
        
          lcd.setCursor(0,1);
          lcd.print("   ");
          if (saveInterval <= 60) {
            lcd.setCursor(0,1);
            lcd.print(saveInterval);
            lcd.setCursor(3,1);
            lcd.print("seconds");
          } else if(saveInterval > 60) {
            minutes = saveInterval / 60;
            lcd.setCursor(0,1);
            lcd.print(minutes);
            lcd.setCursor(3,1);
            lcd.print("minutes");
          }
  
        }
      }
      buttonState = buttonValue1;
                                
    }

 }
  lcd.setCursor(0,3);
  lcd.print("Storing");
  delay(400);
  for (int i = 0; i <= 2; i++) {
    lcd.print(".");
    delay(350);
  }
  return saveInterval;
}

int lcdInt() {
  int buttonValue1;
  int buttonValue2;
  int buttonState;
  int minutes;
  lcd.clear();
  lcd.print("Choose LCD backlight");
  lcd.setCursor(0,1);
  lcd.print("timeout:");
  delay(500);
  lcd.setCursor(0,2);
  lcd.print(lcdInterval);
  lcd.setCursor(3,2);
  lcd.print("seconds");
  buttonState = digitalRead(button1);
 
  {
    buttonValue1 = digitalRead(button1);
    delay(10);
    buttonValue2 = digitalRead(button1);
    if (buttonValue1 == buttonValue2) {
      if (buttonValue1 != buttonState) {
        if (buttonValue1 == LOW) {
          if(lcdInterval >= 10 && lcdInterval < 30) {
            lcdInterval = lcdInterval + 10;
          } else if(lcdInterval >= 30 && lcdInterval < 60) {
            lcdInterval = lcdInterval + 30;
          } else if(lcdInterval >= 60 && lcdInterval < 120) {
            lcdInterval = lcdInterval + 60;
          } else if(lcdInterval >= 120 && lcdInterval < 300) {
            lcdInterval = lcdInterval + 180;
          } else if(lcdInterval >= 300 && lcdInterval < 600) {
            lcdInterval = lcdInterval + 300;
          } else if(lcdInterval >= 600) {
            lcdInterval = 10;
          }
        
          lcd.setCursor(0,2);
          lcd.print("   ");
          if (lcdInterval <= 60) {
            lcd.setCursor(0,2);
            lcd.print(lcdInterval);
            lcd.setCursor(3,2);
            lcd.print("seconds");
          } else if(lcdInterval > 60) {
            minutes = lcdInterval / 60;
            lcd.setCursor(0,2);
            lcd.print(minutes);
            lcd.setCursor(3,2);
            lcd.print("minutes");
          }
          
        }
      }
      buttonState = buttonValue1;
                                
    }
  }
  
  lcd.setCursor(0,3);
  lcd.print("Starting");
  delay(400);
  for (int i = 0; i <= 2; i++) {
    lcd.print(".");
    delay(350);
  }
  return lcdInterval;
}




void lcdPrintDouble( double val, byte precision){


  if(val < 0.0){
    lcd.print('-');
    val = -val;
  }
  if (int(val) < 100) {
    lcd.print(" ");
    lcd.print(int(val));
  } else {
    lcd.print (int(val));  
  }
  if( precision > 0) {
    lcd.print(".");
    unsigned long frac;
    unsigned long mult = 1;
    byte padding = precision -1;
    while(precision--)
      mult *=10;

    if(val >= 0)
       frac = (val - int(val)) * mult;
    else
       frac = (int(val)- val ) * mult;
    unsigned long frac1 = frac;
    while( frac1 /= 10 )
     padding--;
    while(  padding--)
       lcd.print("0");
       lcd.print(frac,DEC) ;
  }
}

and this error mesagges
Code:
sketch_jul04a.cpp: In function 'void setup()':
sketch_jul04a:119: error: 'saveInt' was not declared in this scope
sketch_jul04a.cpp: In function 'void loop()':
sketch_jul04a:183: error: a function-definition is not allowed here before '{' token
sketch_jul04a:357: error: expected `}' at end of input
« Last Edit: July 03, 2012, 10:51:28 pm by rikkifirmansyah » Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're missing a } somewhere in the loop function.

If you indent properly, it'll be obvious. Try going to Tools -> Auto format in the IDE.

By properly, I mean every { should have a corresponding tab, and every } should have a corresponding anti-tab.
Code:
Like {
  This
  Code
  Here {
    That's
    Indented
  }
  properly
}
« Last Edit: July 05, 2012, 12:46:06 pm by WizenedEE » Logged

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

Di dalam funksi // initialize the SD card kamu lupa elsenya!
Code:
 //initialize the SD card

  if (!SD.begin(CS_pin))
    {
      lcd.setCursor(0,0);
      lcd.println ("Card Failure ");
      delay (3000);
      lcd.clear();
      return;
    }
  else {
      lcd.println ("Card Ready");
      delay (3000);
      lcd.clear();
  }

di dalam funksi "int lcdInt()" ada { yang tampa alasan

Code:
 int buttonValue1;
  int buttonValue2;
  int buttonState;
  int minutes;
  lcd.clear();
  lcd.print("Choose LCD backlight");
  lcd.setCursor(0,1);
  lcd.print("timeout:");
  delay(500);
  lcd.setCursor(0,2);
  lcd.print(lcdInterval);
  lcd.setCursor(3,2);
  lcd.print("seconds");
  buttonState = digitalRead(button1);
 
  {...

saveInterval dan lcdInterval kamu tidak pernah initialize. Harus tulis "int saveInterval; int lcdInterval;" sebulumnya
« Last Edit: July 04, 2012, 06:54:35 am by tigertrainer » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Like {
  This
  Code
  Here {
    That's
     Indented
  }
  properly
}
No, it isn't, or Indented and That's would line up.

I know, I'm picky.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Di dalam funksi // initialize the SD card kamu lupa elsenya!
di dalam funksi "int lcdInt()" ada { yang tampa alasan
saveInterval dan lcdInterval kamu tidak pernah initialize. Harus tulis "int saveInterval; int lcdInterval;" sebulumnya
Well, why didn't you say that in the first place? Whatever that is...
Logged

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

I just wrote back in Mochamad Rikki Firmansyah's mother tongue is all.
Logged

Pages: [1]   Go Up
Jump to: