-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.h
210 lines (187 loc) · 4.09 KB
/
functions.h
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <LiquidCrystal.h>
#include <Wire.h>
#include <String.h>
#include <math.h>
LiquidCrystal lcd(8,9,4,5,6,7);
//Pin
#define BUTTON_PIN A0
//Return Values for ReadButtons()
#define BUTTON_NONE 0
#define BUTTON_RIGHT 1
#define BUTTON_UP 2
#define BUTTON_DOWN 3
#define BUTTON_LEFT 4
#define BUTTON_SELECT 5
//Variables
byte buttonPressed = false;
byte buttonReleased = false;
byte buttonWas = BUTTON_NONE;
int SelectingMenu = true;
int scrollMenu = 0;
int scrollElement = 0;
int button = 0;
int menu = 1;
int element = 0;
int MenuChoice;
int ElementChoice;
int sus = 0;
float Answer;
String menu0 = "0123456789";
String menu1 = "+-*/%=";
/*==== Character ================================================*/
byte susr[8] = {
B00000,
B00000,
B01110,
B11000,
B11110,
B11110,
B01010,
B00000
};
/*==== Basic Functions ================================================*/
void setting()
{
//pro-process
Serial.begin(9600); //Serial port set at 9600
Serial.println("Preparing...");//Serial confirm
pinMode(BUTTON_PIN,INPUT); //ensure A0 is an input
digitalWrite(BUTTON_PIN,LOW); //ensure pullup is off on A0
lcd.begin(16,2);
lcd.createChar(0,susr);
}//End void setting()
void intro()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Mirusa's");
delay(500);
lcd.setCursor(5,1);
lcd.print("Calculator");
delay(500);
lcd.clear();
return;
}//End void intro()
void wait(int temp) {
for(int i=0; i<=temp; i++){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Wait A Second");
lcd.print(".");
delay(500);
lcd.print(".");
delay(500);
lcd.print(".");
delay(500);
}
}//End void wait()
/*==== Functions ======================================================*/
int ReadButtons() //read button
{
//Variables
unsigned int buttonVoltage;
byte button = BUTTON_NONE; //return no button pressed
//Read A0 signal
buttonVoltage = analogRead(BUTTON_PIN);
//sense if buttonVoltage fit the keyValues
if( buttonVoltage<60 )
{
button = BUTTON_RIGHT;
}
else if( (buttonVoltage >= 60) && (buttonVoltage <= 200) )
{
button = BUTTON_UP;
}
else if( (buttonVoltage >= 200) && (buttonVoltage <= 400) )
{
button = BUTTON_DOWN;
}
else if( (buttonVoltage >= 400) && (buttonVoltage <= 600) )
{
button = BUTTON_LEFT;
}
else if( (buttonVoltage >= 600) && (buttonVoltage <= 800) )
{
button = BUTTON_SELECT;
}
//see if ther buttons are pressed or released
if( (buttonWas == BUTTON_NONE) && (button != BUTTON_NONE) )//Pa.(N) Pre.(Y)
{
buttonPressed = true;
buttonReleased = false;
}
if( (buttonWas != BUTTON_NONE) && (button == BUTTON_NONE) )//Pa.(Y) Pre.(N)
{
buttonPressed = false;
buttonReleased = true;
}
//save the lastest button value
buttonWas = button;
return button;
}//End byte ReadButtons()
int Menu()//select meuns
{
button = ReadButtons();
if(buttonPressed == true)
{
scrollMenu = button;
buttonPressed = false;
}
if(buttonReleased == true)
{
buttonReleased = false;
switch(scrollMenu)
{
case BUTTON_UP:
{
menu--;
break;
}
case BUTTON_DOWN:
{
menu++;
break;
}
}//End switch
}//End if buttonReleased...
return menu;
}
int Element()
{
button = ReadButtons();
if(buttonPressed == true)
{
scrollElement = button;
buttonPressed = false;
}
if(buttonReleased == true)
{
buttonReleased = false;
switch(scrollElement)
{
case BUTTON_LEFT:
{
element--;
break;
}
case BUTTON_RIGHT:
{
element++;
}
case BUTTON_SELECT:
{
break;
}
}//End switch
}//End if buttonReleased
return element;
}//End int Element()
int limit()
{
}
int cursor()
{
lcd.setCursor(element,0);
lcd.write(sus);
delay(100);
}