Hello : )
i am new to arduino and programming and i have a general question on the following:
I try to read a sensor input and want the arduino to give feedback with a blinking led.
My code looks like that:
int SensorA = 0;
int LedA = 2;
int sensor_val;
void setup() {
Serial.begin(9600);
}
void loop() {
sensor_val = analogRead(SensorA);
Serial.print("Value from sensor");
Serial.println( sensor_val );
delay(4000);
if (sensor_val > 850)
{
Serial.print("not enough");
// should blink slowly
digitalWrite(LedA, HIGH);
delay(1000);
digitalWrite(LedA, LOW);
delay(1000);
}
else if ((sensor_val < 850) && (sensor_val > 500))
{
Serial.print("good");
// should be on constantly
digitalWrite(LedA, HIGH);
delay(5000);
}
else if (sensor_val < 500)
{
Serial.print("too high");
// should blink fast
digitalWrite(LedA, HIGH);
delay(100);
digitalWrite(LedA, LOW);
delay(100);
}
}
What i do not understand: I want the arduino to make a led blink slowly when the value rises above 850, fast when it drops below 500 and
constantly on when the value is in between. As far as i understand i need some kind of loop like »do this while value < than 500« e.g.
If this is correct: can anybody give me a hint or a code how this should look like? And furthermore: If this is correct: how can i make this AND let the arduino do other things like reading another sensor. If i understand the concept of loops and whiles, the arduino won't do anything while the loop is in progress. This is why i do not understand how to structure the sketch..
thank you so much!
sl