[go: up one dir, main page]

0% found this document useful (0 votes)
39 views2 pages

Arduino Coin Acceptor Control Code

This Arduino program controls a coin acceptor and tracks the total amount of coins inserted. It uses an interrupt to count impulses from the coin acceptor and updates the total amount based on the number of impulses detected. The total amount is stored in EEPROM and displayed on a TM1637 display, with different values assigned to different impulse counts.

Uploaded by

ANTONIO COBALLES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Arduino Coin Acceptor Control Code

This Arduino program controls a coin acceptor and tracks the total amount of coins inserted. It uses an interrupt to count impulses from the coin acceptor and updates the total amount based on the number of impulses detected. The total amount is stored in EEPROM and displayed on a TM1637 display, with different values assigned to different impulse counts.

Uploaded by

ANTONIO COBALLES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//Mario's Ideas

//Controlling coin acceptor with Arduino

#include <Arduino.h>
#include <TM1637Display.h>
#include <EEPROM.h>

// Module connection pins (Digital Pins)


#define CLK 3
#define DIO 4

TM1637Display display(CLK, DIO);

// variable use to measuer the intervals inbetween impulses


int i=0;
// Number of impulses detected
int impulsCount=0;
// Sum of all the coins inseted
float total_amount=0;

void setup() {
// pinMode(2, INPUT_PULLUP);
Serial.begin(9600);
display.setBrightness(0x0f);
// Interrupt connected to PIN D2 executing IncomingImpuls function when signal
goes from HIGH to LOW
attachInterrupt(0,incomingImpuls, FALLING);
EEPROM.get(0, total_amount);
display.clear();

void incomingImpuls()
{
impulsCount=impulsCount+1;
i=0;
}

void loop() {
i=i+1;

Serial.print("i=");
Serial.print(i);
Serial.print(" Impulses:");
Serial.print(impulsCount);
Serial.print(" Total:");
Serial.println(total_amount);

if (i>=30 and impulsCount==1){


total_amount=total_amount+2;
impulsCount=0;
EEPROM.put(0, total_amount);
}
if (i>=30 and impulsCount==2){
total_amount=total_amount+1;
impulsCount=0;
EEPROM.put(0, total_amount);
}
if (i>=30 and impulsCount==3){
total_amount=total_amount+0.5;
impulsCount=0;
EEPROM.put(0, total_amount);
}
if (i>=30 and impulsCount==4){
total_amount=total_amount+0.2;
impulsCount=0;
EEPROM.put(0, total_amount);
}
if (i>=30 and impulsCount==5){
total_amount=total_amount+0.1;
impulsCount=0;
EEPROM.put(0, total_amount);
}

if(total_amount<10) display.showNumberDecEx(total_amount*10, 0b10000000, true, 2,


2);
else
display.showNumberDecEx(total_amount*10, 0b00100000, false, 4, 0);
}

You might also like