Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. const byte coinSig = A1;
  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.  
  15. void loop() {
  16.  
  17.  
  18. byte currentCoinSignal = digitalRead(coinSig);
  19.  
  20. if(currentCoinSignal == HIGH){
  21. previousUpdateMillis = millis();
  22. print0flag = true;
  23.  
  24. }
  25.  
  26.  
  27.  
  28.  
  29. if (print0flag == true) {
  30.  
  31. if (millis() - previousUpdateMillis >= updateInterval) {
  32. printBank();
  33. previousUpdateMillis = millis();
  34. }
  35. }
  36.  
  37.  
  38. if(currentCoinSignal != previousCoinSignal){
  39. previousCoinSignal = currentCoinSignal;
  40.  
  41.  
  42. if(currentCoinSignal == HIGH){
  43. bankValue = bankValue + coinValue;
  44. //printBank();
  45. }
  46. }
  47.  
  48. }
  49. void printBank(){
  50. Serial.print("bankvalue: ");
  51. Serial.println(bankValue);
  52. print0flag = false;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement