Hi John,
The game pcb is set to 5 credits and i want the arduino to be able to send the pulse to the board so that it is multiplied 10x5 to give me a total of 50 credits on the board instead of 5, for each single push of the micro switch
I have tried setting the millis() but it gives me an error when ever the Arduino software verify it. but when i write the 50 it doesn't error. How should i correct this.
WHY?!? Why did you remove the " if (buttonState == LOW)"?!? That will credit 10 pulses whenever the input changes, both when the pulse goes LOW and when it goes HIGH. That's 20 output pulses per input pulse.
I did not remove the" If(buttonState==LOW)" ?!?. I am a bit confused as to your last question on this button state
I am a bit confused as to your last question on this button state
The comment says
increment the counter if (buttonState ==Low)
but you never test the value of buttonState in the code.
rick3973:
I have tried setting the millis() but it gives me an error when ever the Arduino software verify it. but when i write the 50 it doesn't error. How should i correct this
The sketch I provided in Reply #6 compiled without error for an Arduino UNO and Arduino Pro Mini. If it does NOT compile without error after you have made a bunch of changes to it, I suspect one of your changes is bad.
What happens when you compile the sketch exactly as it is in Reply #6?
I tried compiling the sketch you posted in Reply #15. I got one warning:
Users/john/Documents/Arduino/sketch_sep21a/sketch_sep21a.ino: In function 'void loop()':
/Users/john/Documents/Arduino/sketch_sep21a/sketch_sep21a.ino:28:81: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
if (buttonState != LastButtonState && CurrentTime - LastButtonChangeTime > 10);
It's warning that you ended that 'if' statement with a semicolon so there are no active statements controlled by the 'if'.
I had written:
// compare the buttonState to its previous state (ignore bounces)
if (buttonState != LastButtonState && currentTime - lastButtonChangeTime > 10)
{
lastButtonChangeTime = currentTime;
// if the state has changed, increment the counter
if (buttonState == LOW)
{
// if the current state is LOW then the input went from off to on:
OutputPulseCounter += 10;
}
}
and you changed it to:
// compare the buttonState to its previous state (ignore bounces)
if (buttonState != LastButtonState && CurrentTime - LastButtonChangeTime > 10);
{
LastButtonChangeTime = CurrentTime;
// if the state has changed, increment the counter if (buttonState ==Low)
{
// if the current state is LOW then the input went from off to on:
OutputPulseCounter += 10;
}
}
Which the warning messages says is equivalent to:
// compare the buttonState to its previous state (ignore bounces)
if (buttonState != LastButtonState && CurrentTime - LastButtonChangeTime > 10)
{
}
{
LastButtonChangeTime = CurrentTime;
// if the state has changed, increment the counter if (buttonState ==Low)
{
// if the current state is LOW then the input went from off to on:
OutputPulseCounter += 10;
}
}
johnwasser:
// Variables will change:
int OutputPulseCounter = 10; // counter for the number of pulse from mini pro to game pcb
WHY?!? Why give 10 pulses of credit each time the sketch restarts?
unsigned long CurrentTime = 50;
WHY?!? Why are you setting the time to 50 and not millis()?!? That will completely muck up the debounce timer!
// if the state has changed, increment the counter if (buttonState ==Low)
{
// if the current state is LOW then the input went from off to on:
OutputPulseCounter += 10;
}
WHY?!? Why did you remove the " if (buttonState == LOW)"?!? That will credit 10 pulses whenever the input changes, both when the pulse goes LOW and when it goes HIGH. That's 20 output pulses per input pulse.
Hi John,
I went back to your original sketch and loaded it to the pro mini, the light on the pro mini board blinks rapid but nothing goes to the gaming board. should i try to set a baud rate to see if it would work
Hey John,
The Arduino sketch that you did for me, i was unable to get to pulse output from it.
After many trials i gave up and stop trying.
Yesterday i started again and finally get it to make 1 output pulse, instead of the 10 that is needed.
Between the last 2
digitalWrite (outputPin, HIGH);
delay (5);
digitalWrite (outputPin, LOW); in your sketch, i inserted delay (5);
it gave me 1 pulse instead of 10 pulse.
if i remove the delay (5); then i does not work.
Can you assist.
Thanks
Harold