Devices & Components
Arduino Nano
4 Digit TM1637 LED Display
Coin Acceptor
Software & Tools
Arduino IDE
Project description
Code
Controlling coin acceptor with Arduino
arduino
1//Mario's Ideas 2//Controlling coin acceptor with Arduino 3 4#include <Arduino.h> 5#include <TM1637Display.h> 6#include <EEPROM.h> 7 8// Module connection pins (Digital Pins) 9#define CLK 3 10#define DIO 4 11 12TM1637Display display(CLK, DIO); 13 14// variable use to measuer the intervals inbetween impulses 15int i=0; 16// Number of impulses detected 17int impulsCount=0; 18// Sum of all the coins inseted 19float total_amount=0; 20 21void setup() { 22 // pinMode(2, INPUT_PULLUP); 23 Serial.begin(9600); 24 display.setBrightness(0x0f); 25 // Interrupt connected to PIN D2 executing IncomingImpuls function when signal goes from HIGH to LOW 26 attachInterrupt(0,incomingImpuls, FALLING); 27 EEPROM.get(0, total_amount); 28 display.clear(); 29 30} 31 32void incomingImpuls() 33{ 34 impulsCount=impulsCount+1; 35 i=0; 36} 37 38void loop() { 39 i=i+1; 40 41 Serial.print("i="); 42 Serial.print(i); 43 Serial.print(" Impulses:"); 44 Serial.print(impulsCount); 45 Serial.print(" Total:"); 46 Serial.println(total_amount); 47 48 if (i>=30 and impulsCount==1){ 49 total_amount=total_amount+2; 50 impulsCount=0; 51 EEPROM.put(0, total_amount); 52 } 53 if (i>=30 and impulsCount==2){ 54 total_amount=total_amount+1; 55 impulsCount=0; 56 EEPROM.put(0, total_amount); 57 } 58 if (i>=30 and impulsCount==3){ 59 total_amount=total_amount+0.5; 60 impulsCount=0; 61 EEPROM.put(0, total_amount); 62 } 63 if (i>=30 and impulsCount==4){ 64 total_amount=total_amount+0.2; 65 impulsCount=0; 66 EEPROM.put(0, total_amount); 67 } 68 if (i>=30 and impulsCount==5){ 69 total_amount=total_amount+0.1; 70 impulsCount=0; 71 EEPROM.put(0, total_amount); 72 } 73 74 if(total_amount<10) display.showNumberDecEx(total_amount*10, 0b10000000, true, 2, 2); 75 else 76 display.showNumberDecEx(total_amount*10, 0b00100000, false, 4, 0); 77}
Downloadable files
untitled
untitled

untitled
untitled

Comments
Only logged in users can leave comments