Coin Collector

From STEAMwiki
Jump to: navigation, search

Sample code for Coin Collector attached to an Arduino. This code was taken from Instructables

const int coinInt = 0;

volatile float coinsValue = 0.00;
int coinsChange = 0;
//A Coin has been inserted flag

void setup()

  attachInterrupt(coinInt, coinInserted, RISING);
  //If coinInt goes HIGH (a Pulse), call the coinInserted function
  //An attachInterrupt will always trigger, even if your using delays

void loop()
  if (coinsChange == 1)
    //Check if a coin has been Inserted
    coinsChange = 0;
    //unflag that a coin has been inserted

    Serial.print("Credit: £");
    //Print the Value of coins inserted

//The function that is called every time it recieves a pulse
void coinInserted(){
  coinsValue = coinsValue + 0.05;
  //As we set the Pulse to represent 5p or 5c we add this to the coinsValue
  coinsChange = 1;
  //Flag that there has been a coin inserted