-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain
More file actions
107 lines (78 loc) · 2.27 KB
/
main
File metadata and controls
107 lines (78 loc) · 2.27 KB
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
#include <HCSR04.h>
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x3F); // set the LCD address to 0x27 for a 16 chars and 2 line display
int show;
UltraSonicDistanceSensor distanceSensor(13, 12); // Initialize sensor that uses digital pins 13 and 12.
void setup () {
Serial.begin(115200); // We initialize serial connection so that we could print values from sensor.
int error;
Serial.println("LCD...");
while (! Serial);
Serial.println("Dose: check for LCD");
// See http://playground.arduino.cc/Main/I2cScanner
Wire.begin();
Wire.beginTransmission(0x27);
error = Wire.endTransmission();
Serial.print("Error: ");
Serial.print(error);
if (error == 0) {
Serial.println(": LCD found.");
} else {
Serial.println(": LCD not found.");
} // if
lcd.begin(16, 2); // initialize the lcd
show = 0;
}
void loop () {
// Every 500 miliseconds, do a using the sensor and print the distance in centimeters.
Serial.println(distanceSensor.measureDistanceCm());
delay(500);
Serial.println(map(distanceSensor.measureDistanceCm(), 50, 0, 0, 100));
if (show == 0) {
lcd.setBacklight(255);
lcd.home(); lcd.clear();
lcd.print(map(distanceSensor.measureDistanceCm(), 50, 0, 0, 100));
delay(1000);
lcd.setBacklight(0);
delay(400);
lcd.setBacklight(255);
} else if (show == 1) {
lcd.clear();
lcd.print("Cursor On");
lcd.cursor();
} else if (show == 2) {
lcd.clear();
lcd.print("Cursor Blink");
lcd.blink();
} else if (show == 3) {
lcd.clear();
lcd.print("Cursor OFF");
lcd.noBlink();
lcd.noCursor();
} else if (show == 4) {
lcd.clear();
lcd.print("Display Off");
lcd.noDisplay();
} else if (show == 5) {
lcd.clear();
lcd.print("Display On");
lcd.display();
} else if (show == 7) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("*** first line.");
lcd.setCursor(0, 1);
lcd.print("*** second line.");
} else if (show == 8) {
lcd.scrollDisplayLeft();
} else if (show == 9) {
lcd.scrollDisplayLeft();
} else if (show == 10) {
lcd.scrollDisplayLeft();
} else if (show == 11) {
lcd.scrollDisplayRight();
} // if
delay(2000);
show = (show + 1) % 12;
} // loop()