-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbathroomlock.ino
194 lines (165 loc) · 3.29 KB
/
bathroomlock.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//Code by Leonard Henry Phelan IV
//Currently all rights reserved
//leonardhphelaniv@gmail.com
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
//Defenitions for I2C display
#define I2C_ADDR 0x3F
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
//Commands for locking and unlocking servo
#define lock servo.write(90)
#define unlock servo.write(65)
//Pin variables, preprocesor directive for speed
//Button
#define btn 10
//Pezio Buzzer
#define pez 8
//LED
#define led 13
//Coin acceptor
#define cac 12
//Credit reset button
#define rst 6
//Servo pin
#define svo 9
//Credit counter
int credits = 0;
//Used for For(){} statements
int i = 0;
//[P]ulse [C]ount
int pc = 0;
//[D]elay [C]ount
int dc = 0;
Servo servo;
boolean once = false;
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
//Various title screens of LCD
void title1 ()
{
lcd.clear();
lcd.home();
lcd.print("Welcome to Lenny's");
lcd.setCursor(0,1);
lcd.print("Bathroom! There is a");
lcd.setCursor(0,2);
lcd.print("50c admission fee.");
lcd.setCursor(0,3);
lcd.print("Please insert coins.");
}
void title2 ()
{
lcd.clear();
lcd.home();
lcd.print("In event of theft,");
lcd.setCursor(0,1);
lcd.print("buzzer will sound");
lcd.setCursor(0,2);
lcd.print("until your visit");
lcd.setCursor(0,3);
lcd.print("has been paid for.");
}
void title3 ()
{
lcd.clear();
lcd.home();
lcd.print("Design copyright (C)");
lcd.setCursor(0,1);
lcd.print("2014 by Leonard");
lcd.setCursor(0,2);
lcd.print("Henry Phelan IV.");
lcd.setCursor(0,3);
lcd.print("(774) 994-3082");
}
//Screen when coins are inserted... Constantly refreshes
void credit1 ()
{
lcd.home();
lcd.print(" :Credits inserted:");
lcd.setCursor(1,2);
lcd.print("<<===-- --===>>");
lcd.setCursor(9,2);
if (credits < 10) {lcd.print("0");}
lcd.print(credits);
}
/*
int pulse ()
{
while (!digitalRead(cac) && once == false) {}
once = true;
while (digitalRead(cac)) {}
while (!digitalRead(cac)) {
delay(1);
i++;
if (i > 100) {
if (pc == 1) {return 25;}
if (pc == 2) {return 10;}
if (pc == 3) {return 5;}
}
}
pc++;
}*/
int pulse ()
{
pc = 0;
pcloop:
while (!digitalRead(cac)) {}
dc = 0; pc++;
while (digitalRead(cac)) {
delay(1);
dc++;
if (dc > 100 || pc == 3) {
goto end;
}
}
goto pcloop;
end:
if (pc == 1) {return 25;}
if (pc == 2) {return 10;}
if (pc == 3) {return 5;}
}
void setup()
{
servo.attach(svo);
lcd.begin (20,4,LCD_5x8DOTS);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
pinMode(btn, INPUT_PULLUP);
pinMode(pez, OUTPUT);
pinMode(led, OUTPUT);
pinMode(cac, INPUT);
pinMode(rst, INPUT_PULLUP);
}
void loop()
{
while(!digitalRead(cac)) {
title1();
timeout();
title2();
timeout();
title3();
timeout();
lcd.clear();
}
while (credits < 50) {
credits += pulse();
credit1();
}
}
void timeout()
{
for (int i = 0; i <= 5000; i++) {
if (digitalRead(cac)) {
break;
}
delay(1);
}
}