1
2
3
4#include <Arduino.h>
5#include <TM1637Display.h>
6#include <EEPROM.h>
7
8
9#define CLK 3
10#define DIO 4
11
12TM1637Display display(CLK, DIO);
13
14
15int i=0;
16
17int impulsCount=0;
18
19float total_amount=0;
20
21void setup() {
22
23 Serial.begin(9600);
24 display.setBrightness(0x0f);
25
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}