-
Notifications
You must be signed in to change notification settings - Fork 0
/
pedometer.ino
132 lines (106 loc) · 2.28 KB
/
pedometer.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
/*
pedometer glue
#########Button Screen Interaction #####################
#######################################################
*/
#include <avr/sleep.h>
#include "UI.h"
#include "IMU.h"
#define timeoutDelay 20000
// BUTTON SETUP; TWO BUTTONS: ONE FOR NAVIGATION; THE OTHER FOR SELECTION
const uint8_t navBtn = 7;
const uint8_t selBtn = 6;
bool navBtnLastState = HIGH;
bool selBtnLastState = HIGH;
bool navBtnState;
bool selBtnState;
unsigned long navLastDebounce = 0;
unsigned long selLastDebounce = 0;
unsigned long timeout = 0;
int debounceDelay = 50;
uint8_t testPinA0 = A0;
void testInt()
{
digitalWrite(testPinA0,LOW);
ack();
detachInterrupt(digitalPinToInterrupt(3));
}
void wake()
{
sleep_disable();
ack();
detachInterrupt(digitalPinToInterrupt(3));
}
void sleepNow()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
noInterrupts();
sleep_enable();
attachInterrupt(digitalPinToInterrupt(3),wake,FALLING);
interrupts();
sleep_cpu();
}
void setup()
{
Serial.begin(115200);
pinMode(testPinA0,OUTPUT);
pinMode(navBtn,INPUT_PULLUP);
pinMode(selBtn,INPUT_PULLUP);
setupSensor();
configureLSM9DS1Interrupts();
setupScreen();
welcomeScreen();
}
void loop()
{
// ADCSRA = 0; //turn of ADC
// checkInt();
menu();
// attachInterrupt(digitalPinToInterrupt(3),testInt,LOW);
uint8_t readNavBtn = digitalRead(navBtn);
uint8_t readSelBtn = digitalRead(selBtn);
if(readNavBtn != navBtnLastState)
{
navLastDebounce = millis();
}
if(readSelBtn != selBtnLastState)
{
selLastDebounce = millis();
}
if((millis() - navLastDebounce) > debounceDelay)
{
if(readNavBtn != navBtnState)
{
navBtnState = readNavBtn;
if(navBtnState == LOW)
{
screenOn();
moveMenu();
goHome();
timeout = millis();
}
}
}
if((millis() - selLastDebounce) > debounceDelay)
{
if(readSelBtn != selBtnState)
{
selBtnState = readSelBtn;
if(selBtnState == LOW)
{
screenOn();
switchPage();
timeout = millis();
}
}
}
navBtnLastState = readNavBtn;
selBtnLastState = readSelBtn;
refreshPage();
// Serial.println(countStep());
if((millis() - timeout) > timeoutDelay )
{
screenOff();
}
digitalWrite(testPinA0,HIGH);
}