currently, i am programming a vending machine that is supposed to gives you candy if a certain amount of money is given. the money is registered with light barriers (LED and photo resistor). I want to read out my photo resistors only 5 times per second. unfortunately I have no idea how this should work.
Thank you for your help!
best regards and have a nice day
Take a look at the BlinkWithoutDelay example in the IDE. Change the period to make the repeat 5 times per second and instead of changing the state of an LED read the sensor
I want to add up the signals and show them on an LCD. my problem is that the whole program should continue. therefore a delay is not appropriate. Unfortunately.
I forgot to write that
UKHeliBob pointed you to the BlinkWithoutDelay example in the IDE, which teaches you exactly that.
Using millis() for timing, instead of the blocking delay().
This sketch is the essence of it.
Leo..
unsigned long interval = 200; // 1/5 of a second
unsigned long previousMillis; // last time we looked
void setup() {
}
void loop() {
if (millis() - previousMillis >= interval) { // if time has passed
// do whatever you have to do with the sensor here
previousMillis = millis(); // when done, reset the timer
}
}