strange token problem

Hi,:) I got a strange problem, the error code is'a function-definition is not allowed here before '{' token' but I check many times , I CANT find any problems that mess up tokens

void updateTime(unsigned long current_time) {
  if(iMinutes >= 0) {
    if(current_time - prevClockTime > UPDATE_TIME_INTERVAL) {
      // Increase time
      iMinutes++;
      if(iMinutes >= 60) {
        iMinutes = 0;
        iHour++;
        if(iHour > 12) {
          iHour = 1;
          (iAmPm == 0) ? iAmPm=1 : iAmPm=0;
          if(iAmPm == 0) {
            iWeek++;
            if(iWeek > 7)
              iWeek = 1;
            iDay++;
            if(iDay > 30)  // Yes. day is not exact.
              iDay = 1;
          }
        }
      }
      prevClockTime = current_time;
    }
  }
  else {
    displayMode = DISPLAY_MODE_START_UP;
  }
}

Thanks!

Posting a little piece of your code (and most likely NOT the piece that is causing the problem) is not going to get any useful answers.

Post the full code AND post the actual error message.

It sounds like you are trying to define one function inside another - accidentally or otherwise.

…R

Hi,

Here’s my full code

//cloud smartwatch test program v 1.3.1
//Copyright. 2014 Ren Zhiyang All Rights Reserved
//Cloud Development and Sdudy Center.
String comdata = "";    
#include <Adafruit_ssd1306syp.h>
#include "DHT.h"
////////////////////////////////
//////////////////define compass
#include <Wire.h> //I2C Arduino Library
#define address 0x1E //0011110b, I2C 7bit address of HMC5883
/////////////////////////////////
// define GY-61 accerlatmotor pin
const int xpin = A1;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A3;                  // z-axis (only on 3-axis models)

////////////////////////////////
////////define OLED

#define SDA_PIN 8     //OLED pin
#define SCL_PIN 9     //OLED pin
Adafruit_ssd1306syp display(SDA_PIN,SCL_PIN);

////////////////////////////////////////////
//////////////define DH11 temperature sensor
#define DHTTYPE DHT11
#define DHTPIN 2      //temperature sensor pin
DHT dht(DHTPIN, DHTTYPE);

///////////////////////////////////////////
//////////////////////define button input
const int smsButtonPin = 7 ;  // the number of the pushbutton pin
const int menuButtonPin =6;
const int appButtonPin = 5;
const int okButtonPin = 4;
int smsButtonState = 0;
int menuButtonState = 0;
int appButtonState = 0;
int okButtonState = 0;
/////////////////////////////////////////
/////////////////////////////TIME
#define UPDATE_TIME_INTERVAL 60000
byte iMonth = 1;
byte iDay = 1;
byte iWeek = 1;    // 1: SUN, MON, TUE, WED, THU, FRI,SAT
byte iAmPm = 0;    // 0:AM, 1:PM
byte iHour = 0;
byte iMinutes = 0;
unsigned long current_time = 0;
unsigned long prevClockTime = 0;
///////////////////////////////////////////
/////////////////////////define MODE switch index
#define DISPLAY_MODE_START_UP 0
#define DISPLAY_MODE_CLOCK 1
#define DISPLAY_MODE_SMS 0
#define DISPLAY_MODE_APP 0
/////////////////////////////////
byte displayMode = DISPLAY_MODE_START_UP;


void setup()
{
    /////////////////////////////////////////////////
    //////////////////////////////////RetroWatch said that the serial opened will cause a serious problem
    ////////////////////////test that if something not right 
    Serial.begin(9600);
    //////////////////////////////////////////////////
    /////////////////////////////////////////////////
    delay(100);
    display.initialize();
    ////////////////////////////initialized the pushbutton pin as an input
    pinMode(smsButtonPin, INPUT);
    pinMode(menuButtonPin, INPUT);
    pinMode(appButtonPin, INPUT);
    pinMode(okButtonPin, INPUT);
    ///////////////////////////////////////////////////////
    
    Wire.begin();
    //Put the HMC5883 IC into the correct operating mode
    Wire.beginTransmission(address); //open communication with HMC5883
    Wire.write(0x02); //select mode register
    Wire.write(0x00); //continuous measurement mode
    Wire.endTransmission();
}

void loop()
{
    
    //display temperature and humandity
    buttonInput();
    //////////////////////////////////////////////////////
    current_time = millis();
    updateTime(current_time);
    /////////////////////////////////////////////////////
    onDraw(current_time);/////////////////////need to add more index..
    
}
 
void temandhum()
{
    int h = dht.readHumidity();
    int t = dht.readTemperature();
}


///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////call message display button
void smsCall()
{
  
    Serial.println("sms");
    delay(25);
    while (Serial.available() > 0)    //Test whether there is data in serial
    {
        comdata += char(Serial.read());
        delay(2);
    }
    if (comdata.length() > 0)
    {
        //Print SMS received
        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.println(comdata);
        display.update();
        delay(2000);
        comdata = "";
        display.clear();
    } 
    else
    {
        display.setTextSize(2);
        display.setTextColor(WHITE);
        display.setCursor(0,30);
        display.println("NO MESSAGE");
        display.update();
        delay(1000);
        display.clear();
    }
  
}

////////////////////////////////////////////////////////////////////////
/////////////////////////////// GY-271 accelerate output data to android
void acclerOutput()
{
  int x = analogRead(xpin); 
  delay(1); // 
  int y = analogRead(ypin); // 
  delay(1);   
  int z = analogRead(zpin); 
  
  float zero_G = 512.0; //ADC is 0~1023  the zero g output equal to Vs/2 
                       //ADXL335 power supply by Vs 3.3V
  float scale = 102.3;  //ADXL335330 Sensitivity is 330mv/g 
                        //330 * 1024/3.3/1000  
                                                                                
  Serial.print(x);
  Serial.print("\t"); 
  Serial.print(y); 
  Serial.print("\t"); 
  Serial.print(z); 
  Serial.print("\n"); 
 delay(50);
}


/////////////////////////////////////////////////////////////
//////////////////////////////////////////////compass GY-271
void compass()
{
  int a,b,c; //triple axis data

  //Tell the HMC5883 where to begin reading data
  Wire.beginTransmission(address);
  Wire.write(0x03); //select register 3, X MSB register
  Wire.endTransmission();
  
 
 //Read data from each axis, 2 registers per axis
  Wire.requestFrom(address, 6);
  if(6<=Wire.available()){
    a = Wire.read()<<8; //X msb
    a |= Wire.read(); //X lsb
    c = Wire.read()<<8; //Z msb
    c |= Wire.read(); //Z lsb
    b = Wire.read()<<8; //Y msb
    b |= Wire.read(); //Y lsb
  }
  
  //Print out values of each axis
  Serial.print("a: ");
  Serial.print(a);
  Serial.print("  b: ");
  Serial.print(b);
  Serial.print("  c: ");
  Serial.println(c);
  
  delay(250);
}

///////////////////////////////////////////////
/////////////////////////CHECK BUTTON on main screen
void buttonInput()
{
  smsButtonState = digitalRead(smsButtonPin);
  appButtonState = digitalRead(appButtonPin);
  menuButtonState = digitalRead(menuButtonPin);
  if (smsButtonState == HIGH)
  {
    displayMode == DISPLAY_MODE_SMS;
  }
  if (appButtonState == HIGH)
  {
    displayMode == DISPLAY_MODE_APP;
  }
}
////////////////////////////////////////////////////
//////////////////////////////////////check button on sms/app page
void menuButtonInput()
{
  smsButtonState = digitalRead(smsButtonPin);
  appButtonState = digitalRead(appButtonPin);
  menuButtonState = digitalRead(menuButtonPin);
  okButtonState = digitalRead(okButtonPin);
  if (smsButtonState == HIGH) 
  {
    rollUp();
  }
  else if (appButtonState == HIGH)
  {
    rollDown();
  }
  else if (menuButtonState == HIGH)
  {
    displayMode = DISPLAY_MODE_CLOCK;
  }
  
  

////////////////////////////////////////////////////
////////////////////////////////////update time/////
void updateTime(unsigned long current_time) {
  if(iMinutes >= 0) {
    if(current_time - prevClockTime > UPDATE_TIME_INTERVAL) {
      // Increase time
      iMinutes++;
      if(iMinutes >= 60) {
        iMinutes = 0;
        iHour++;
        if(iHour > 12) {
          iHour = 1;
          (iAmPm == 0) ? iAmPm=1 : iAmPm=0;
          if(iAmPm == 0) {
            iWeek++;
            if(iWeek > 7)
              iWeek = 1;
            iDay++;
            if(iDay > 30)  // Yes. day is not exact.
              iDay = 1;
          }
        }
      }
      prevClockTime = current_time;
    }
  }
  else {
    displayMode = DISPLAY_MODE_START_UP;
  }
}
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

void onDraw(unsigned long current_time)
{
  if(!isDisplayTime(currentTime))    // Do not re-draw at every tick
    return;
  
  if(displayMode == DISPLAY_MODE_START_UP) {
    drawStartUp();
  }
  else if(displayMode == DISPLAY_MODE_CLOCK) {
    drawClock();
  {
  else if(displayMode == DISPLAY_MODE_SMS) {
    drawSms();
  }
  else if(displayMode == DISPLAY_MODE_APP) {
    drawApp();
  }
}
///////////////////////////////////////////////////
////////////////////////////////////////////////
void rollUp() {
  
}
/////////////////////////////////////////////////////
/////////////////////////////////////////////////
void rollDown() {
  
}
////////////////////////////////////////////////////
//////////////////////////////////////////////////
void drawClock()
{
  display.clear();
  display.println(iMinute

Thanks!

There is a mismatch in the number of "{" vs "}" brackets.

I check many times, who can point it out for me?

thanks

firecloud: I check many times, who can point it out for me?

I asked you to post the error report but you have not done so. It may give the line number.

I copied your code into my editor (Geany). There is a missing } on line 238. And a wrong { on line 284. And a missing } on line 308.

The moral of the story - use a decent editor.

...R

Look at this function void menuButtonInput() and count the brackets.

else if (menuButtonState == HIGH) { displayMode = DISPLAY_MODE_CLOCK; }

missing closing bracket here

//////////////////////////////////////////////////// ////////////////////////////////////update time///// void updateTime(unsigned long current_time) { if(iMinutes >= 0) { if(current_time - prevClockTime > UPDATE_TIME_INTERVAL) { // Increase time iMinutes++; if(iMinutes >= 60) { iMinutes = 0; iHour++; if(iHour > 12) {

@Vaclav: Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” button above the posting area (It looks like a scroll with < > inside it).