Hi there,is their anybody who can help me to get this code working? (down below)
I,m making a coin counting system for my jukebox.
I have 2 pulseswitches.
1 pulse switch wich must count up 1 number everytime it,s pressed.
And 1 pulse switch wich must countdown 1 number when it,s pressed
The count up works but the count down not.
I think because their is no mathmatic code present to add up and to countdown the som of the pulses.
Can anyone please help me?
Thank you very much.
</>
#include <Bounce2.h>
const int buttonPin1 = 2;
const int buttonPin2 = 4;
Bounce pushbutton1 = Bounce(buttonPin1, 10); // 10 ms debounce
Bounce pushbutton2 = Bounce(buttonPin2, 10); // 10 ms debounce
void setup() {
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(A0, OUTPUT);
Serial.begin(9600);
Serial.println("Pushbutton Bounce library test:");
}
byte previousState = HIGH; // what state was the button last time
unsigned int count = 0; // how many times has it changed to low
unsigned long countAt = 0; // when count changed
unsigned int countPrinted = 0; // last count printed
void loop() {
if (pushbutton1.update()) {
if (pushbutton1.fallingEdge()) {
count = count + 1;
countAt = millis();
}
} else {
if (pushbutton2.update()) {
if (pushbutton2.fallingEdge()) {
count = count - 1;
countAt = millis();
}
}
if (count != countPrinted) {
unsigned long nowMillis = millis();
if (nowMillis - countAt > 100) {
Serial.print("count= ");
Serial.println(count);
countPrinted = count;
}
if (count >=0 )
digitalWrite(A0, HIGH);// Start relays
if (count <= 0)
digitalWrite(A0, LOW);// Stop relays
}
}
}