-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCH925.ino
74 lines (49 loc) · 1.85 KB
/
CH925.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//aaaa
//La papa con salsa no sabe mejor
const int coinSelector = 4;
const float signalCostFactor = 0.5; // Each signal pulse is worth 5p
//rama de la rama
//Marzo 27, 2020.
//Nueva rama por metodo del click
int signalValue = 0; // For storing value from analog input
int state; // Current state
int lastState = 0; // Last state
float balance = 0; // Pence
float coinValue = 0; // Curent coin value
int update = 1; // Used for sending an update
long updateDebounceTime = 0; // The last time we sent an update
long updateDebounceDelay = 250; // Update 500ms after last singal pulse
void setup() {
pinMode(13, OUTPUT); // Status LED
Serial.begin(9600); // Setup serial at 9600 baud
delay(2000); // Don't start main loop until we're sure that the coin selector has started
Serial.println("Ready..");
void loop() {
signalValue = digitalRead(coinSelector); // Read analog value from coin selector
if (signalValue > 0) {
state = 1; // State is 1 as we're high
} else {
state = 0;
if (update == 0) {
if ((millis() - updateDebounceTime) > updateDebounceDelay) {
Serial.print("Coin Value: ");
Serial.println(coinValue); // WARNING: The coin value will be wrong if coins are inserted within the updateDebounceDelay, adjust the delay and test
Serial.print("Balance: ");
Serial.println(balance); // This should be the most accurate as we should get the same ammount of pulses even if multiple coins get inserted at once
coinValue = 0;
update = 1;
}
}
}
if (state != lastState) {
if (state == 1) {
balance = balance + signalCostFactor;
coinValue = coinValue + signalCostFactor;
updateDebounceTime = millis();
update = 0;
}
lastState = state;
}
delay(1);
}
/*pollito lofiu*/