-1

I am getting a compilation error: expected unqualified-id before 'if' . Btu I have check all the semicolons . Please help finding my error. The rest of the message error reads

C:\Users\jecalderon\Documents\Arduino\Codigo_AS7262_Investigacion_V2\Codigo_AS7262_Investigacion_V2.ino:35:1: error: expected unqualified-id before 'if'
 if (currentMillis - previousMillis >= interval) {
 ^~
C:........\Codigo_AS7262_Investigacion_V2.ino:40:1: error: expected unqualified-id before 'if'
 if (send) {
 ^~

exit status 1

Compilation error: expected unqualified-id before 'if'
#include <Wire.h>
#include "Adafruit_AS726x.h"
//create the object
Adafruit_AS726x ams;
//buffer para leer valores en bruto
uint16_t sensorValues[AS726x_NUM_CHANNELS];
//buffer para  guardar los valores calibrados( no esta siendo utilizado en este codigo)
//float calibratedValues[AS726x_NUM_CHANNELS];
unsigned long previousMillis = 0;
const long interval = 250;
bool send = false;
void setup() {
  Serial.begin(115200);
  while (!Serial) {
    // inicializa el pin digital LED_BUILTIN como un output.
    pinMode(LED_BUILTIN, OUTPUT);

    //inicia y permite la comunicacion con el sensor
    if (!ams.begin()) {
      Serial.println("could not connect to sensor! Please check your wiring.");
      
        
    }
  }
}
void loop() {
  //lee la temperatura del sensor
  //uint8_t temp = ams.readTemperature();
  //ams.drvOn(); // descomentar esto si quieres usar el led del sensor para hacer medidas
  ams.startMeasurement();  //begin a measurement
  //permite que el sensor lea la data cuando este disponible
  unsigned long currentMillis = millis();
};
//ams.drvOff(); //descomentar esto si quieres usar el led del sensor para hacer medidas
if (currentMillis - previousMillis >= interval) {
  previousMillis = currentMillis;
  send = true;
}

if (send) {
  //lee los valores!
  ams.readRawValues(sensorValues);
  //ams.readCalibratedValues(calibratedValues);

  //Serial.print("{");
  //Serial.print("Temp: ");
  //Serial.print(temp);
  //Serial.print(",");
  //Serial.print(" Violet: ");
  Serial.print(sensorValues[AS726x_VIOLET]);
  Serial.print(",");
  //Serial.print(" Blue: ");
  Serial.print(sensorValues[AS726x_BLUE]);
  Serial.print(",");
  //Serial.print(" Green: ");
  Serial.print(sensorValues[AS726x_GREEN]);
  Serial.print(",");
  //Serial.print(" Yellow: ");
  Serial.print(sensorValues[AS726x_YELLOW]);
  Serial.print(",");
  //Serial.print(" Orange: ");
  Serial.print(sensorValues[AS726x_ORANGE]);
  Serial.print(",");
  //Serial.print(" Red: ");
  Serial.print(sensorValues[AS726x_RED]);
  //Serial.print("}");

  Serial.println();

  send = false;
}
6
  • 1
    If your original issue is solved, please mark the answer. Do not change this question into something else, instead post a new question. You can link back to this question to provide some background. However, each question shall be self-contained. Sep 27, 2023 at 6:18
  • Thank you or breaking my troubleshooting process. Publishing Updates have always been very effective to reach solutions to very difficult subjects. I suggest you not to edit or remove any edit that specifically calls to be an UPDATE. Now, I had to issue credit to an answer that although close to a solution, had not accomplished to satisfy the objective. This is bad enough added to the fact that you had down voted my original post that where active receiving feedbacks from community contributions. Sep 28, 2023 at 1:12
  • Disclaimer: I did not vote down or edited your question. However, I feel with the one who did. -- You might want to take the tour (again) and read some of the help center pages. This site is not a forum, and it might not support your process of troubleshooting. This is a Q&A site, with specific questions and answers, if there are some. If your issue is not solved, do not mark an answer and clarify why it does not answer the specific issue. But if your process leads to another issue, please post that in a new question. Otherwise you render all work done to the former useless. Sep 28, 2023 at 5:43
  • Your update is not lost. You can see it if you follow the "edited" link. You can use that to post a new question. Please learn about this site before blaming. Sep 28, 2023 at 5:44
  • I consider to watch closely people down voting on threads but offering no significant contribution to the post. I have been around for 10 years and find this down voting activity motivated for the wrong reasons. I pointing to the number of negative credits when compared to positive votes. Hope my feedback is taken well by the moderators and administrators. Sep 29, 2023 at 0:58

1 Answer 1

0

Check your braces. Use Control-T to autoformat your code and the error will become apparent.

This is your entire loop function. Everything after this is is outside of the function.

void loop() {
  //lee la temperatura del sensor
  //uint8_t temp = ams.readTemperature();
  //ams.drvOn(); // descomentar esto si quieres usar el led del sensor para hacer medidas
  ams.startMeasurement();  //begin a measurement
  //permite que el sensor lea la data cuando este disponible
  unsigned long currentMillis = millis();
};
2
  • Thankyou for the contribution. Sep 27, 2023 at 2:52
  • Did it solve your problem?
    – Delta_G
    Sep 27, 2023 at 14:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.