Brand new to Arduino. Bought a kit from Amazon to get started, have done the obligatory "Hello, World" and the onboard LED blink, so I at least know that it works, lol.
I am in a bit of a bind, however. I actually bought the Arduino kit to do a specific project with it, and I am unsure where to start so I can learn the necessary skills to do it.
Without too much detail, I need it to do different tasks on subsequent presses of the same button.
I would like it to do 3 different things -
1st one is to play the "Sad Trombone" tones after the button press and display a message on the 1602 LCD that says "Please Try Again"
2nd press would be to play an audio file that I will record in whatever format is necessary, and play another message on the LCD to the affect of "Hmm, Try one more" or something
and then the 3rd one I would like it to display a countdown and then close a relay at the end to activate an external device.
I have tried looking online to see if I can accomplish these things with this kit, and so far it seems like it may be possible with a little bit of additional hardware (speaker) and the adequate time.
But if this requires something other than an Uno, relay, 1602 display, relay, and assorted relays, then I need to know asap so I can purchase what I need.
Any help that can be given would be greatly appreciated.
Yes, because otherwise it stays the same in the loop() and repeats itself so you need to move to the next number, but not to trigger the next stuff() until a button press. There may be other solutions of course
Configure the pin you are using for the button as INPUT_PULLUP. This way you don't need an external pullup or pulldown resistor. LOW will indicate button has been pressed.
Code your project in steps adding functionality in each step. I would suggest your first step would be to correctly detect a button press. Second step would be to increment a counter and display the counter. Third step would be to test counter values and call a different function for each value. Last step would be to add the hardware for the LCD and to play the tones.
Post your sketch, well formated, with well-tempered comments and in so called code tags "< code >" and a detailed circuit diagram to see how we can help.
Well,
I have been able to get it to play a single sound at the press of a button. I have an mp3 player board attached and works, but the only way I have been able so far to get the sound to play once after the first button press is the exit(0) command, and that stops the code completely until reset.
Here is what I have so far
#include <ezButton.h>
#include "DYPlayerArduino.h"
// Initialise the player, it defaults to using Serial.
DY::Player player;
#define LOOP_STATE_STOPPED 0
#define LOOP_STATE_STARTED 1
ezButton button(2); // create ezButton object that attach to pin 2;
int loopState = LOOP_STATE_STOPPED;
void setup() {
player.begin();
player.setVolume(30);
button.setDebounceTime(50); // set debounce time to 50 milliseconds
}
void loop() {
button.loop(); // MUST call the loop() function first
if (button.isPressed()) {
if (loopState == LOOP_STATE_STOPPED)
loopState = LOOP_STATE_STARTED;
else // if(loopState == LOOP_STATE_STARTED)
loopState = LOOP_STATE_STOPPED;
}
if (loopState == LOOP_STATE_STARTED) {
player.playSpecified(2);
delay(5500);
exit (0) ;
}
}
I did modify the ezbutton code to use pin 2 instead of pin 7 and it works fine.
This is my first time doing any coding like this, and with working 65 hours a week, and basically being a single parent this time of year, I don't have a lot of "spare" time, so I really appreciate any help I can get.
What I am looking for is the code above (or similar) and it needs to -
I am not sure how to merge it with my code, as this is my first time working with arduino, and I don't understand the syntax. I haven't done much in the way of coding for more than 25 years, and that was on an Apple 2
That is why I am asking for help.
I have managed to get the player to work and to play the desired sound when the button is pressed, BUT it either loops endlessly (no exit command), or it plays one time and exits (with exit(0)), but then won't do anything without being reset manually.
I can see that it increments a variable by reading the StateChangeDetection example. That much was obvious. What I don't understand is how to go about implementing that code in my project.
Use the StateChangeDetection example as a starting point and add a function for each of the actions that should occur when the counter value is 0, 1, 2 etc. Let's call then func0, func(1) and func2()
Then, if counter equals 0 call func0(), if it equals 1 call func1() and if it equals 2 call func2() and you are nearly there. There is more to it if you only want each function to be executed once rather than repeatedly, but you can add that once the basic idea works