-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathOS.pde
147 lines (123 loc) · 3.67 KB
/
OS.pde
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
//
// OS.pde
//
// Copyright 2011 Hicaduda. All rights reserved.
//
/*
hicaduda.com || http://github.com/sgonzalez/Arduino-Sensor-System
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software in binary form, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#include <LiquidCrystal.h> // we need this library for the LCD commands
#include "Ping.h"
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
Ping ping = Ping(2,74,29);
const int NUMAPPS = 6;
int pressed;////For button next app
int currentApp;
long randNumber;
long cdsSensor;
void genRand() {
randNumber = random(1000); //0 to 999
}
void getCdS() {
cdsSensor = analogRead(1);
}
void setup() {
lcd.begin(16, 2); // need to specify how many columns and rows are in the LCD unit
lcd.print("Super Cool LCD ");
delay(3000);
pinMode(13, INPUT); //Button
randomSeed(analogRead(0)); //picks random numbers from analog pin 0
genRand();
getCdS();
lcd.clear();
}
void loop() {
pressed = digitalRead(13);
if (pressed == HIGH) {
pressed = 0;
currentApp++;
if (currentApp > NUMAPPS) currentApp = 0;
genRand();
} else {
pressed = 0;
}
switch (currentApp) {
case 0:
ping.fire();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("====Distance====");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print(ping.inches());
lcd.print("in ");
lcd.print(ping.centimeters());
lcd.print("cm");
break;
case 1:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("===Temperature==");
lcd.setCursor(0,1);
lcd.print(" ");
//lcd.print(currentC,1);
lcd.print("F ");
//lcd.print(currentF,1);
lcd.print("C");
break;
case 2:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("=Random Number==");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print(randNumber); //Three digit random number
break;
case 3:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("======Time======");
lcd.setCursor(0,1);
lcd.print(" ");
//lcd.print(currentC,1); //Something like 9:24:10 AM
break;
case 4:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("======Date======");
lcd.setCursor(0,1);
lcd.print(" ");
//lcd.print(currentC,1); //Something like 19/4/2011
break;
case 5:
getCdS();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("===Light Level==");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print(cdsSensor/12); //Divisor may vary by CdS cell
lcd.print("%");
break;
}
delay(100); // gives time to ignore switch bounce, implement better system for future
}