-
Notifications
You must be signed in to change notification settings - Fork 4
/
04_01_ex4-time_since_pin_reset.c
38 lines (34 loc) · 1.21 KB
/
04_01_ex4-time_since_pin_reset.c
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
/* building off the system liquid crystal library */
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
// added per sparkfun tutorial at
// https://learn.sparkfun.com/tutorials/basic-character-lcd-hookup-guide
const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
unsigned int t0;
void setup() {
// reading from digital pin 3 which is manually toggeled from High to Low
// with a breadboarding wire
pinMode(3,INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print("d3 low for (ms)");
t0 = millis();
}
void loop() {
// write time in the second row
//lcd.setCursor(column, row);
if (digitalRead(3)==HIGH) {
t0 = millis();
lcd.setCursor(0, 1);
lcd.print("0 ");
} else { // ie, digital 3 is LOW
lcd.setCursor(0, 1);
lcd.print(millis() - t0);
delay(random(100, 900));
}
// Note, this is buggy. Afer a reset, the second row of the display will read something like 0953
// after being in 2953 when the D3 signal wire was at LOW and the counter was incementing properly
// How can we fix this?
}