Skip to main content
Post Reopened by JRobert, Greenonline, sempaiscuba
Post Closed as "Opinion-based" by jsotola, VE7JRO, Rohit Gupta
added 109 characters in body
Source Link
Wizard
  • 141
  • 4

I have an Arduino vehicle and I upload projects to it that I want them to function once I use a strong light on a light sensor attached to A4 analog pin. So far, I have used the following code:

void setup() {
    while (analogRead(A4) < 900) {}
}
void loop() {
  // do something with the vehicle
}

I know it's a bad design, but there's a limitation that I can't use the loop() function for this (it's actually a limitation of a specific IDE usage scenario), I need to do it in the setup() function, so I would like to know if I'm doing any harm to Arduino or the light sensor by using the previous code. Should I also use delay() or millis() in this while loop? The sensing of the strong light doesn't have to be accurate.

I have an Arduino vehicle and I upload projects to it that I want them to function once I use a strong light on a light sensor attached to A4 analog pin. So far, I have used the following code:

void setup() {
    while (analogRead(A4) < 900) {}
}

I know it's a bad design, but there's a limitation that I can't use the loop() function for this (it's actually a limitation of a specific IDE usage scenario), so I would like to know if I'm doing any harm to Arduino or the light sensor by using the previous code. Should I also use delay() or millis() in this while loop? The sensing of the strong light doesn't have to be accurate.

I have an Arduino vehicle and I upload projects to it that I want them to function once I use a strong light on a light sensor attached to A4 analog pin. So far, I have used the following code:

void setup() {
    while (analogRead(A4) < 900) {}
}
void loop() {
  // do something with the vehicle
}

I know it's a bad design, but there's a limitation that I can't use the loop() function for this (it's actually a limitation of a specific IDE usage scenario), I need to do it in the setup() function, so I would like to know if I'm doing any harm to Arduino or the light sensor by using the previous code. Should I also use delay() or millis() in this while loop? The sensing of the strong light doesn't have to be accurate.

Source Link
Wizard
  • 141
  • 4

Using a while loop in setup function to read sensor data

I have an Arduino vehicle and I upload projects to it that I want them to function once I use a strong light on a light sensor attached to A4 analog pin. So far, I have used the following code:

void setup() {
    while (analogRead(A4) < 900) {}
}

I know it's a bad design, but there's a limitation that I can't use the loop() function for this (it's actually a limitation of a specific IDE usage scenario), so I would like to know if I'm doing any harm to Arduino or the light sensor by using the previous code. Should I also use delay() or millis() in this while loop? The sensing of the strong light doesn't have to be accurate.