Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const byte coinSig = 4;
- bool previousCoinSignal = false;
- const float coinValue = 0.05;
- float bankValue = 0.00;
- unsigned long previousUpdateMillis = 0;
- unsigned long updateInterval = 110;
- bool print0flag = false;
- void setup() {
- Serial.begin(9600);
- pinMode(coinSig, INPUT_PULLUP);
- previousCoinSignal = digitalRead(coinSig);
- digitalWrite(coinSig, LOW);
- }
- void loop() {
- byte currentCoinSignal = digitalRead(coinSig);
- if(currentCoinSignal == HIGH){
- Serial.println("coin!");
- previousUpdateMillis = millis();
- print0flag = true;
- }
- if(print0flag == true){
- if(millis() - previousUpdateMillis >= updateInterval){
- printBank();
- print0flag = false;
- }
- }
- if(currentCoinSignal != previousCoinSignal){
- previousCoinSignal = currentCoinSignal;
- if(currentCoinSignal == HIGH){
- bankValue = bankValue + coinValue;
- //printBank();
- }
- }
- }
- void printBank(){
- Serial.print("bankvalue: ");
- Serial.println(bankValue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement