Not declared in scope, I have no idea why this isn't working

THIS IS THE ERROR MESSAGE

/Users/Desktop/Our_main_sketch/Our_main_sketch.ino: In function 'void loop()':
Our_main_sketch:51:5: error: 'setDecimalsI2C' was not declared in this scope
setDecimalsI2C(0b00000100)
^~~~~~~~~~~~~~
/Users/Desktop/Our_main_sketch/Our_main_sketch.ino: At global scope:
Our_main_sketch:128:1: error: expected unqualified-id before '{' token
{
^
exit status 1
'setDecimalsI2C' was not declared in this scope

THIS IS THE CODE
#include <Servo.h>

unsigned long startTime;
unsigned long currentTime;
const unsigned long period = 1000;
const int Blueservostart = 14000;
const int Pinkservostart = 14000;
const int Aquaservostart = 14000;
const int Blueservostop = 15000;
const int Pinkservostop = 15000;
const int Aquaservostop = 15000;
Servo Blueservo;
Servo Pinkservo;
Servo Aquaservo;
byte i;
int speakerPin = 6;

#include <Wire.h>

const byte s7sAddress = 0x71;

unsigned int counter = 100;
char tempString[10];

void setup() {
Wire.begin();
Serial.begin(9600);
clearDisplayI2C();
s7sSendStringI2C("-HI-");
delay(1000);
setBrightnessI2C(255);
delay(1500);
clearDisplayI2C();

pinMode(7,INPUT_PULLUP); // speaker output
while(digitalRead(7)==HIGH);
Blueservo.attach(8);
Pinkservo.attach(9);
Aquaservo.attach(10);
pinMode(6,OUTPUT);
startTime = millis();
}

void loop() {

currentTime = millis()-startTime;
sprintf(tempString, "%4d", counter);
s7sSendStringI2C(tempString);
if((currentTime>startTime)&(currentTime<10001)){
if (counter < 10000)
setDecimalsI2C(0b00000100)
else
setDecimalsI2C(0b00001000)
}
if(counter>0){
counter--;
delay(100);
}

if((currentTime>Blueservostart)&(currentTime<Blueservostop)){
Blueservo.write(90);}
if(currentTime>Blueservostop)
{Blueservo.write(0);}

if((currentTime>Pinkservostart)&(currentTime<Pinkservostop)){
Pinkservo.write(90);}
if(currentTime>Pinkservostop)
{Pinkservo.write(0);}

if((currentTime>Aquaservostart)&(currentTime<Aquaservostop)){
Aquaservo.write(90);}
if(currentTime>Aquaservostop)
{Aquaservo.write(0);}

if (currentTime>max(Aquaservostop,max(Blueservostop,Pinkservostop))){
startTime = millis();
counter = 100;}

}
void play( char note, int beats)
{
int numNotes = 14;
char notes[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B', ' '};
int frequencies[] = {131, 147, 165, 175, 196, 220, 247, 262, 294, 330, 349, 392, 440, 494, 0};

int currentFrequency = 0;
int beatLength = 150;
{
if (notes[i] == note)
{
currentFrequency = frequencies[i];
}
}

tone(speakerPin, currentFrequency, beats * beatLength);
delay(beats * beatLength);
delay(50);
}

void s7sSendStringI2C(String toSend)
{
Wire.beginTransmission(s7sAddress);
for (int i=0; i<4; i++)
{
Wire.write(toSend[i]);
}
Wire.endTransmission();
}
void clearDisplayI2C()
{
Wire.beginTransmission(s7sAddress);
Wire.write(0x76); // Clear display command
Wire.endTransmission();
}

void setBrightnessI2C(byte value)
{
Wire.beginTransmission(s7sAddress);
Wire.write(0x7A); // Set brightness command byte
Wire.write(value); // brightness data byte
Wire.endTransmission();
}

{
Wire.beginTransmission(s7sAddress);
Wire.write(0x77);
Wire.write(decimals);
Wire.endTransmission();
}

Use code tags.

Can you see how this function is incorrect with where the { and }.

Please post your code in code tags.

Again there is code outside of functions.

Use code tags.

Do you see e.g. char notes[] in your post? That's why we ask to use code tags so the forum software does not think that e.g. [] is a special character.

Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

The IDE has a very useful function called Auto Format (in the Tools menu. If you use that, you should be able to see straight away what is wrong. After an Auto Format, your code looks like

void setBrightnessI2C(byte value)
{
  Wire.beginTransmission(s7sAddress);
  Wire.write(0x7A); // Set brightness command byte
  Wire.write(value); // brightness data byte
  Wire.endTransmission();
}

{
  Wire.beginTransmission(s7sAddress);
  Wire.write(0x77);
  Wire.write(decimals);
  Wire.endTransmission();
}

As @Idahowalker pointed out, the second part is outside a function.

You're also missing some semi-colons; this is visible after the Auto Format. E.g.

  if ((currentTime > startTime) & (currentTime < 10001)) {
    if (counter < 10000)
      setDecimalsI2C(0b00000100)
      else
        setDecimalsI2C(0b00001000)
      }

where the second setDecimalsI2C in not aligned at the same level as the first one.

And lastly the setDecimalsI2C function is nowhere to be found in the code.

//Edit: I see you have another topic about setDecimalsI2C as well. Do not crosspost, it wastes people's time.

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Simple check - count the opening braces { then count the closing braces }.

If the numbers are different then that's at least part of the problem. Each { must have a corresponding }. Same for ( and ).

Steve

You can do this even simpler. Click on an opening brace or bracket and the closing one is highlighted. Click on the closing one and the opening one is highlighted.

Until the IDE editor was "improved" some time ago then clicking on an opening or closing brace or bracket would highlight the code enclosed by the pair of braces or brackets. What a shame that this was removed

Thanks, didn't know that. I am still working with 1.8.13

It was changed a long while ago and I suspect that whoever "improved" the editor didn't even know that the facility was there. Thinking about it, the highlighting was probably activated by a double click adjacent to the brace/bracket

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.