-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeedometer_gps.ino
More file actions
102 lines (93 loc) · 2.22 KB
/
speedometer_gps.ino
File metadata and controls
102 lines (93 loc) · 2.22 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
/*
GPS Speedometer Firmware
Taylor Daniska
*/
#include <SoftwareSerial.h>
#include <Stepper.h>
#include <TinyGPS.h>
TinyGPS gps;
SoftwareSerial ss(10, 11);
static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);
const int stepsPerRevolution = 200;
const int buttonPin = 2;
Stepper myStepper(stepsPerRevolution, 5,6,8,7);
int currentStep = 0;
int speedValue = 0;
int buttonState = 0;
boolean startup = true;
int incomingByte;
int stepValue = 0;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
ss.begin(9600);
}
void loop()
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < 10); //change 10 to adjust delay for gps
if (startup == true) {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
for (int i=0; i <= 30; i++) {
myStepper.step(-1);
delay(10);
1}
}
Serial.print("Startup");
for (int i=0; i <= 68; i++) {
Serial.print("for");
myStepper.step(1);
delay(10);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
startup = false;
for (int i=0; i <= 44; i++) {
Serial.print("return");
myStepper.step(-1);
delay(10);
}
break;
}
}
if(startup == true) {
for (int i=0; i <= 68; i++) {
Serial.print("for");
myStepper.step(-1);
delay(10);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
startup = false;
for (int i=0; i <= 53; i++) {
Serial.print("return");
myStepper.step(-1);
delay(10);
}
break;
}
}
}
startup = false;
}
Serial.print("Run");
speedValue = (gps.f_speed_kmph()*0.621371);
delay(10);
stepValue = map(speedValue, 0, 80, 0, 63);
if (stepValue > currentStep) {
myStepper.step(1);
currentStep = currentStep + 1;
}
else if (stepValue < currentStep) {
myStepper.step(-1);
currentStep = currentStep - 1;
}
}