Hi,
Im a coding amateur here looking to code some stuff for my school project.
I was wondering what is the best way to activate the LittleBits DC Motor at fixed intervals (say once every 20 minutes?)
I did some research and found this thing called "While Loops", is that the best way to do something like this?
Many thanks! Your help will be appreciated!
Usually done through the millis() timing function, like this:
#define INTERVAL 1200000; // 20 minutes
uint32_t previousRun = -INTERVAL; // ensure run upon startup
loop() {
if (millis() - previousRun > INTERVAL) {
previousRun = millis();
runMotor();
}
}
The millis() register is an unsigned long int, overflowing every 49 days or so. 20 minutes is dead easy.