/*************************** Expensive Coin Counter From Payphone Autopsy Day March 20, 2013 Cable coming from the coin counter mechanism Green: Ground White: Quarter Red: Dime Blue: Nickel ****************************/ // These integers refer to the pins on the Arduino board const int quarterPin = 7; const int dimePin = 2; const int nickelPin = 4; const int quarterValue = 25; const int dimeValue = 10; const int nickelValue = 5; int quarterStatus = 0; int dimeStatus = 0; int nickelStatus = 0; const int ledPin = 13; int coinStatus = 0; int prevStatus = 0; int total = 0; int printMoney(int n) { int dollars; int cents; dollars = n / 100; cents = n % 100; Serial.print("$"); Serial.print(dollars); Serial.print("."); if (cents < 10) { Serial.print("0"); } Serial.println(cents); return 1; } void setup() { pinMode(ledPin, OUTPUT); // declare LED as output pinMode(quarterPin, INPUT); // declare switch input pinMode(dimePin, INPUT); // declare switch input pinMode(nickelPin, INPUT); // declare switch input Serial.begin(38400); Serial.println("EXPENSIVE COIN COUNTER"); printMoney(total); } void loop(){ int val = LOW; val = digitalRead(quarterPin); digitalWrite(ledPin, val); if (val == HIGH) { if (quarterStatus == 0) { total += quarterValue; printMoney(total); dimeStatus = 1; delay(250); } } else { dimeStatus = 0; } val = digitalRead(nickelPin); digitalWrite(ledPin, val); if (val == HIGH) { if (nickelStatus == 0) { total += nickelValue; printMoney(total); dimeStatus = 1; delay(250); } } else { dimeStatus = 0; } val = digitalRead(dimePin); digitalWrite(ledPin, val); if (val == HIGH) { if (dimeStatus == 0) { total += dimeValue; printMoney(total); dimeStatus = 1; delay(250); } } else { dimeStatus = 0; } }
You need to enable Javascript in your browser to edit pages.
help on how to format text