Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. const byte coinSig = 4;
  2. bool previousCoinSignal = false;
  3. const float coinValue = 0.05;
  4. float bankValue = 0.00;
  5.  
  6. unsigned long previousUpdateMillis = 0;
  7. unsigned long updateInterval = 110;
  8. bool print0flag = false;
  9. void setup() {
  10. Serial.begin(9600);
  11. pinMode(coinSig, INPUT_PULLUP);
  12. previousCoinSignal = digitalRead(coinSig);
  13.  
  14. digitalWrite(coinSig, LOW);
  15. }
  16.  
  17. void loop() {
  18.  
  19. byte currentCoinSignal = digitalRead(coinSig);
  20.  
  21. if(currentCoinSignal == HIGH){
  22. Serial.println("coin!");
  23. previousUpdateMillis = millis();
  24. print0flag = true;
  25.  
  26. }
  27.  
  28.  
  29.  
  30.  
  31. if(print0flag == true){
  32.  
  33. if(millis() - previousUpdateMillis >= updateInterval){
  34. printBank();
  35. print0flag = false;
  36. }
  37. }
  38.  
  39.  
  40. if(currentCoinSignal != previousCoinSignal){
  41. previousCoinSignal = currentCoinSignal;
  42.  
  43.  
  44. if(currentCoinSignal == HIGH){
  45. bankValue = bankValue + coinValue;
  46. //printBank();
  47. }
  48. }
  49.  
  50. }
  51. void printBank(){
  52. Serial.print("bankvalue: ");
  53. Serial.println(bankValue);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement