I want to decrease Analog input on andruino in a loop but it is not hapenning.
It does happen when i declare variable in software.
I am trying to decrease analog input by one like (–) inside a loop but it is not happening.
im trying to build volt down voltramp with analog inputs that declare start, time delay and in software is declared 0 .
There are two ways how I can interpret your question.
1) The first one is read the analog inputs in a loop; the below code reads all 6 inputs in sequence and prints the reading.
for (int pin = A0; pin <= A5; pin++)
Serial.print("Pin "); Serial.print(pin); Serial.print(": "); Serial.println(analogRead(pin));
This works because A0 is defined as being the pin 14 (and A5 as being pin 19); this is on a UNO, other boards might have different numbering but the principle stays the same.
2) The second interpretation is that you read an analog input and next want to modify the value that was read. The below code demonstrates this. It will toggle the onboard LED (on an UNO) a number of times. The analog value sets the number of times as well as the delay between the toggles.
// read analog input
int analogvalue = analogRead(A0);
// do something with it
while (analogvalue != 0)
// toggle onboard LED
digitalWrite(13, digitalRead(13) ^ 1);
// use analog value as delay
// decrement analog value
Note that if your reading is e.g. 400, it will loop 400 times with delays from 400 to 0 (so total delay is approx. 400 * 200 ms = 80 seconds before the analog input is read again).