I've got a sketch up and running for a game I've built for my Grandkids Christmas .. .. ..
I'm using a Mega 2560 and after some angst and a few more grey hairs I've got most things as I want them but I've one action I cannot fathom ..
Is there a command I can put into a sketch to invoke a reset, that is, as though I'd pressed the reset button on the Arduino .. .. .. i've looked everywhere I can think of and found nothing .. .. .
Why not write a function that resets any relevant variables to initial values and call it when you want to restart the game ? Resetting the Arduino seems to be a very clumsy way to achieve what you want.
The simple answer to that one is I've been coding about 3 weeks now and I wouldn't know where to start with that .. sounds complicated. Invoking a reset, gets me the desired effect and a methodology I can understand.
I still have a lot of other problems to solve with this yet and at the moment, it's still a prototype on a breadboard .. at some stage I've got to make a pretty case for it with hot moulded acrylic and then build it all into the case.
I've appended my sketch so that you can see what I'm doing.. .. the commented out section at the top is because at the moment, the wave files play when the button is pressed and I'm trying to get them to play coincident with each new LED .. I thought that would do it but it keeps playing the last wave file over and over .. I think because PIN 13 is also the I/O pin for the onboard LED and it's conflicting but I'm not sure.
I'm learning fast, but not that fast !!
Thanks for your time .. ..
S
Edit: it won't allow me to post the code 'exceeds maximum allowed length' . wife used to say that !
@johnwasser,
I thought it had been discussed that using an IO pin, which reverts to an input when reset is applied, resulted in reset not being applied long enough for reset to be effective?
I've never tried it myself. A low for 2.5uS is needed per the datasheet section 29.5, Table 29-11.
Document Atmel-8271J-AVR- ATmega-Datasheet_11/2015
I would guess pulldowns with pins connected to +5 when pressed from this:
if (digitalRead(2) == HIGH ||
digitalRead(3) == HIGH ||
digitalRead(4) == HIGH ||
digitalRead(5) == HIGH ||
digitalRead(6) == HIGH) {
started = true; //start the game if any button is pressed
}
I would suggest using pinMode (pinX, INPUT_PULLP);
wire the button to connect to Gnd, and then look for a LOW vs a HIGH.
Alleviate any chance to accidentally connect +5 to GND and short out the power supply.
Thanks for the advice, I see what you mean. There are external pulldown resistors on the buttons and also an MC14490P debounce chip .. .. .. .
To achieve that however, I'd have to dismantle and rebuild the hardware and then re-write the code and given that it took me 2 weeks to get the thing working, albeit with some 'creases' to iron out, I think that's a bridge too far for me now.
I will however, keep a note for a future investigation.