Curled braces imbroglio

Hi everyone !I've tried to compile a code with allows me to send information to Max Msp with a teensy 3 board. My code was working quite good since I tried to inject a few new lines to make max Msp automatically detect the port were my board is connected. But I have a 'not declared in the scope' error. I think that it could come from one or several missing or extra curled braces but I'm not able to find were the problem could come from... Does anyone could help me with this ?

Code_teensy_test_autoconnexion.ino (4.0 KB)

Maybe you meant countervalue:

long contervalue = 0; // computer value

It is always best to post your code inline together with the exact error message.

Post your code inline ... using the code tags ( </> ) in the forum editor. Including an attachment is a pain for anyone wanting to debug your code.

Yes ... :slight_smile: there we go !

// Arduino serial tester
long randomvalue = 0;//random value
long contervalue = 0; // computer value
int serialvalue; //value for serial input
int started = 0; // flag for whether we've received serial yet

//flowmeter
int flowPin = 0;
double flowRate;
volatile int count;
//buttons
int bouton1 = 1;
int bouton2 = 2;
int bouton3 = 3;
int bouton4 = 4;
int bouton5 = 5;
int bouton6 = 6;
int bouton7 = 7;
int bouton8 = 8;
int bouton9 = 9;
int bouton10 = 10;
int bouton11 = 11;
int bouton12 = 12;
// buttonstates
int etatbouton1 = 0;
int etatbouton2 = 0;
int etatbouton3 = 0;
int etatbouton4 = 0;
int etatbouton5 = 0;
int etatbouton6 = 0;
int etatbouton7 = 0;
int etatbouton8 = 0;
int etatbouton9 = 0;
int etatbouton10 = 0;
int etatbouton11 = 0;
int etatbouton12 = 0;

void setup() {
//init serial com
  Serial.begin(9600);  

//flowmeter
  pinMode(flowPin, INPUT);
  attachInterrupt(0, Flow, RISING);
//buttons
  pinMode(bouton1, INPUT);
  pinMode(bouton2, INPUT);
  pinMode(bouton3, INPUT);
  pinMode(bouton4, INPUT);
  pinMode(bouton5, INPUT);
  pinMode(bouton6, INPUT);
  pinMode(bouton7, INPUT);
  pinMode(bouton8, INPUT);
  pinMode(bouton9, INPUT);
  pinMode(bouton10, INPUT);
  pinMode(bouton11, INPUT);
  pinMode(bouton12, INPUT);
}

void loop() {
  //flowmeter
  count = 0;
  interrupts();
  noInterrupts();
  //Accelerometer
  int sensorValuex = analogRead(A0);
  int sensorValuey = analogRead(A1);
  int sensorValuez = analogRead(A2);
  //Buttonstates
  int etatbouton1 = digitalRead(bouton1);
  int etatbouton2 = digitalRead(bouton2);
  int etatbouton3 = digitalRead(bouton3);
  int etatbouton4 = digitalRead(bouton4);
  int etatbouton5 = digitalRead(bouton5);
  int etatbouton6 = digitalRead(bouton6);
  int etatbouton7 = digitalRead(bouton7);
  int etatbouton8 = digitalRead(bouton8);
  int etatbouton9 = digitalRead(bouton9);
  int etatbouton10 = digitalRead(bouton10);
  int etatbouton11 = digitalRead(bouton11);
  int etatbouton12 = digitalRead(bouton12);
  //Potentiometers
  int Pot1 = analogRead(A3);
  int Pot2 = analogRead(A4);
  int Pot3 = analogRead(A5);
  int Pot4 = analogRead(A6);
  int Pot5 = analogRead(A7);
  int Pot6 = analogRead(A8);

if(Serial.available()) // check to see if there's serial data in the buffer
{
serialvalue = Serial.read(); // read a byte of serial data
started = 1; // set the started flag to on
}
if(started) { // loop once serial data has been received
randomvalue = random(1000); // pick a new random number
Serial.print(countervalue); // print the counter
Serial.print(" "); // print a space
Serial.print(randomvalue); // print the random value
Serial.print(" "); // print a space
Serial.print(serialvalue); // echo the received serial value
Serial.println(); // print a line-feed
countervalue = (countervalue+1)%1000; // increment the counter
delay(100); // pause
}
  //Print values

  //flowmeter
  Serial.print(flowRate);
  Serial.print("\t");
  //Accelerometer
  Serial.print(sensorValuex);
  Serial.print("\t");
  Serial.print(sensorValuey);
  Serial.print("\t");
  Serial.print(sensorValuez);
  Serial.print("\t");
  //Buttons
  Serial.print(etatbouton1);
  Serial.print("\t");
  Serial.print(etatbouton2);
  Serial.print("\t");
  Serial.print(etatbouton3);
  Serial.print("\t");
  Serial.print(etatbouton4);
  Serial.print("\t");
  Serial.print(etatbouton5);
  Serial.print("\t");
  Serial.print(etatbouton6);
  Serial.print("\t");
  Serial.print(etatbouton7);
  Serial.print("\t");
  Serial.print(etatbouton8);
  Serial.print("\t");
  Serial.print(etatbouton9);
  Serial.print("\t");
  Serial.print(etatbouton10);
  Serial.print("\t");
  Serial.print(etatbouton11);
  Serial.print("\t");
  Serial.print(etatbouton12);
  Serial.print("\t");
  //Potentiometers
  Serial.print(Pot1);
  Serial.print("\t");
  Serial.print(Pot2);
  Serial.print("\t");
  Serial.print(Pot3);
  Serial.print("\t");
  Serial.print(Pot4);
  Serial.print("\t");
  Serial.print(Pot5);
  Serial.print("\t");
  Serial.println(Pot6);

  delay(150);  //stability delay
}
void Flow() {
  count++;  //when this function is called count increases by 1
}

Errors now :

/Users/myname/Desktop/Code_teensy_test_autoconnexion/Code_teensy_test_autoconnexion.ino: In function 'void loop()':
/Users/myname/Desktop/Code_teensy_test_autoconnexion/Code_teensy_test_autoconnexion.ino:92:14: error: 'countervalue' was not declared in this scope
 Serial.print(countervalue); // print the counter
              ^

exit status 1

Compilation error: 'countervalue' was not declared in this scope

Well, where is this variable defined ?

Not here although the name looks similar:

??? what is the purpose of this?

when you start numbering variable names it usually means you should read about arrays...

oh god you were right !!! This was the problem !!!

Sorry but I really don't know :wink:

Definitely right !!! Thank you so much 6v6gt !!!

Thanks JML but I don't know what you mean... :wink: I'm so far from understanding coding methods...

something like this

// boutons
const byte boutons[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
const byte nbBoutons = sizeof boutons / sizeof * boutons;
int etatBoutons[nbBoutons];

// potentiomètres
const byte potards[] = {A3, A4, A5, A6, A7, A8};
const byte nbPotards = sizeof potards / sizeof * potards;
int etatPortards[nbPotards];

void setup() {
  Serial.begin(9600);
  pinMode(flowPin, INPUT);                      // flowmeter
  for (auto& b : boutons) pinMode(b, INPUT);    // boutons
  attachInterrupt(0, Flow, RISING);
}

void loop() {
  //Accelerometer
  int sensorValuex = analogRead(A0);
  int sensorValuey = analogRead(A1);
  int sensorValuez = analogRead(A2);
  //Buttonstates
  for (byte i = 0; i < nbBoutons; i++) etatBoutons[i] = digitalRead(boutons[i]);

  //Potentiometers
  for (byte i = 0; i < nbPotards; i++) etatPortards[i] = analogRead(potards[i]);

...

be careful though because you have a button supposedly on pin 1 which is the Tx pin of your Serial port

Oh !!! well done ! thanks a lot J-M-L !!! I've been learning a lot with with you sent to me !!

About this advice :

"be careful though because you have a button supposedly on pin 1 which is the Tx pin of your Serial port..."

Is it so important ? Because the controller is working quite good and does not seem to be doing weird things because of that ...

well Tx is an output pin and a button is an input pin... what could go wrong...

hi JML, I've been testing the code you sent to me but something appears to be wrong... Output of the Arduino IDE says that A8 was not declared in the scope... What do you think the problem could be ?

Well you were using A8 in the original code so I used it too. It means you were likely compiling for a MEGA. If you compile for a UNO there is no analog pin A8, so that would be the issue.

Yes !! that was the problem... I was testing the code you gave me with an Arduino instead of the usual teensy 3.2 I'm working with ! So many thanks JML ! you're a boss :+1:
Could you help me with my last problem now ? I've been trying lots of ways to Serial print the values of Pots and buttons in rows, I mean something like this, in this order : Flowmeter / Accelerometer / Buttons / Potentiometer rows

In the serial monitor it has to look like this :

0.00 452 664 542 0 0 0 0 0 0 0 0 0 0 0 0 1023 1023 1023 1023 1023 1023
0.00 452 664 542 0 0 0 0 0 0 0 0 0 0 0 0 1023 1023 1023 1023 1023 1023
0.00 452 664 542 0 0 0 0 0 0 0 0 0 0 0 0 1023 1023 1023 1023 1023 1023
and so on...

Thanks for the time you are spending in this :wink:

how do you want it to look ?

Sorry, I made a translation mistake ! I didn't meant rows, but columns, and that should look like something like this :
1st column : Flowmeter value (pin 0)
2d column : Accelerometer x axis value (A0)
3d column : Accelerometer y axis value (A1)
4th column : Accelerometer z axis value (A2)
5th column : Button 1 value (pin1) // I will soon change this !! :slight_smile:
6th column : Button 2 value (pin2)
7th column : Button 3 value (pin3)
8th column : Button 4 value (pin4)
9th column : Button 5 value (pin5)
10th column : Button 6 value (pin6)
11th column : Button 7 value (pin7)
12th column : Button 8 value (pin8)
13th column : Button 9 value (pin9)
14th column : Button 10 value (pin10)
15th column : Button 11 value (pin11)
16th column : Button 12 value (pin12)
17th column : Potentiometer 1 value (A3)
18th column : Potentiometer 2 value (A4)
19th column : Potentiometer 3 value (A5)
20th column : Potentiometer 4 value (A6)
21th column : Potentiometer 5 value (A7)
22th column : Potentiometer 6 value (A8)