I am a complete newbie at this. I am wondering about the timers on the Arduino uno.
Can the timers interpret how long a button has been pressed or can the timer tell when a sensor was activated and then deactivated?
I am trying to create a device that has two functions. If the button (or sensor) is held down for 3 or more seconds then one audio file is played from the sd card. If the button is held down for 3 minutes or more, a different audio is played from the sd card.
Eventually, I would like to be able to play random tracks from each group.
Is this possible with an Arduino or is this more of a job for a raspberry?
I really hope it is possible with an Arduino because I am just learning programming and python is out of my league right nowš
Arduino's are very good at this sort of thing.
Setting up the actual timers is a bit advanced for someone just starting out, but fortunately Arduino provides 2 function's that make it easy and they called the millis() and micros() functions.
millis() keeps track of the number of milliseconds since power up. micros() does the same for microseconds.
The "Blink Without Delay" example sketch gives a basic introduction to using the millis() function and here is a more in depth look: Part 1 Multi-tasking the Arduino
Thank you for the very useful information. So.. using the output when pressed and output when released: I can start a timer when the button is pressedā¦this would be my first output. the Arduino can track the time until the button is released and then the second output can be an āifā statement that determines if the amount of time equals decision A or decision B?
All I need to do is use the repeating millisdelay.
I just set my delay or for the light to stay on for four minutes or 240000 mills.
Then have the Arduino check if the light is on or not. If it is, then it plays the designated audio track from the sd card. If the light is off, then it plays the other designated track.
#include <millisDelay.h>
int led = 13;
// Pin 13 has an LED connected on most Arduino boards.
bool ledOn = false; // keep track of the led state
millisDelay ledDelay;
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT); // initialize the digital pin as an output.
digitalWrite(led, LOW); // turn led off
ledOn = false;
// start delay
ledDelay.start(1500);
}
void checkToggleLed() { // led task
// check if delay has timed out
if (ledDelay.justFinished()) {
ledDelay.repeat(); // start delay again without drift
// toggle the led
ledOn = !ledOn;
if (ledOn) {
digitalWrite(led, HIGH); // turn led on
} else {
digitalWrite(led, LOW); // turn led off
}
}
}
void loop() {
checkToggleLed(); // check if should toggle led based on timer
}
Is this the right track? I understand that I havenāt changed any of the commands from the original code yet.
I just got the parts in for making the wav file reader so I can use the sd card. Now I need to program that in there⦠back into studying I goš¤