-
Notifications
You must be signed in to change notification settings - Fork 7
/
cycloduino.ino
1217 lines (894 loc) · 30.6 KB
/
cycloduino.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// cycloduino - ciclocomputer bike speedometer
// Augusto Carmo (carmolim) 2012 - https://github.com/carmolim/cycloduino
// Inspired on the work of Amanda Ghassae - http://www.instructables.com/id/Arduino-Bike-Speedometer/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
*/
/*
TODO
- evitar leituras erradas quando o ima estiver passando com baixa velocidade ou parar na frente do REED
- porque a leitura da cadência não está fazendo com que inicie a contagem do movingTime?
LOG
///
- create a file name with date and time - I'll need a DS1302 or DS1307
- think is going to be easier to just add a sequencial number and make a verification if the file name already exists
SPEED
/////
OK - current speed
OK - average speed
OK - top speed
CADENCE
///////
OK - how to calculate cadence
OK - max cadence
OK - average cadence
CALORIES
////////
The Journal of Sports Sciences provides a calorie expenditure formula for each gender.
Men: Calories Burned = ((Age x 0.2017) + (Weight x 0.09036) + (Heart Rate x 0.6309) - 55.0969) x Time / 4.184
Women: Calories Burned = ((Age x 0.074) -- (Weight x 0.05741) + (Heart Rate x 0.4472) - 20.4022) x Time / 4.184.
Read more: http://www.livestrong.com/article/221621-formula-for-calories-burned-during-exercise/#ixzz2HWlKgfgJ
Male: ((-55.0969 + (0.6309 x HR) + (0.1988 x W) + (0.2017 x A))/4.184) x 60 x T
Female: ((-20.4022 + (0.4472 x HR) - (0.1263 x W) + (0.074 x A))/4.184) x 60 x T
where:
HR = Heart rate (in beats/minute)
W = Weight (in kilograms)
A = Age (in years)
T = Exercise duration time (in hours)
other ref: http://www.shapesense.com/fitness-exercise/calculators/heart-rate-based-calorie-burn-calculator.aspx
HEART RATE
//////////
Equation for Determination of Maximum Heart Rate Based on Age
Maximum Heart Rate (beats/minute) = 208 - (0.7 x age)
*/
// LIBRARIES
////////////
#include <Adafruit_BMP085.h> // Barometer
#include <Adafruit_GFX.h> // LCD graphics
#include <Adafruit_PCD8544.h> // LCD
#include <Wire.h>
//#include <SD.h>
// INTERFACE
////////////
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 7, 6);
const int buttonPin = 8; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int graphSteps = 42; // number of lines used for build the graph
int screen = 8; // variable for reading the pushbutton status
int buttonState = 0; // variable for reading the pushbutton status
int graphPosition = 0; // stores the actual position in the array
int speedGraph[graphSteps]; // stores the last 42 speed reads to draw the speed graphic
//CYCLES
////////
const int oneSecCycle = 1000; // 1 second
unsigned long before1Sec = 0;
const int buttonDebounce = 200; // 500 milisegundos
unsigned long beforeButton = 0;
// SENSORS
//////////
const int speedReed = A0; // speed reed switch
const int cadenceReed = A1; // cadence reed switch
// BAROMETER
////////////
Adafruit_BMP085 bmp; // create a barometer object
const int altSamplesAmount = 50; // number of samples to make the altSamples
int altSamplesStep = 0;
float altSamples[altSamplesAmount]; // stores the last readings
float averageAltitude = 0.0;
float altitude = 0.0; // stores the actual altitude in meters
float lastAltitude = 0.0; // stores the last altitude value
float totalAscent = 0.0; // sum of all ascents
float maxAltitude = 0.0; // higher altitude in the ride
float minAltitude = 900.0; // lowest altitude in the ride
const int filterAltitude = 1; // diference between altitude and last altitude
int altCalibration = 101490; //
// LOG
//////
//File myFile; // object to handle with the file in the SD
String logLine; // stores each log line before it is recorded in th SD
char logName[] = "RIDE_00.csv"; // create an array that contains the name of our file.
// USER INFO
////////////
const int age = 24; // age in years of the user
float weight = 77.5; // weight in Kg
// HEART RATE
/////////////
float heartRate = 0.00; // current bpm
float avgHeartRate = 0.00; // average bpm
float maxHeartRate = 0.00; // max bpm
float minHeartRate = 0.00; // min bpm
// CALORIES
///////////
float caloriesBurned = 0.00; // total calories burned
// TOTAL MEASURES
/////////////////
const int maxReedCounter = 80; // min time (in ms) of one rotation (for debouncing)
float odometer = 0; // total distante
int loopCounter = 0; // how many times the loop run before the ride started
// PER RIDE
///////////
long rideTime = 0; // total time of the ride
long movingTime = 0; // only the moving time
long millisCount = 0; // stores the number of cicles runned in the interrupt
float rideDistance = 0.00; // total distance of the ride in Km
boolean rideStarted = false; // if the bike is moving = true
boolean moving = false; // if the bike is moving = true
// SPEED VARIBALES
//////////////////
long speedTimer = 0; // time between one full rotation (in ms)
long speedNumberSamples = 0; // total of revolutions made by the front wheel
float speedSamplesSum = 0.00; // sum of all the speeds collected
float circumference = 210.0; // lenght of the wheel
float kph = 0.00; // speed in kph
float mph = 0.00; // speed in mph
float topSpeed = 0.00; // top speed of the ride
float avgSpeed = 0.00; // average speed of the ride
int speedReedVal = 0; // ?? stores if the switch is open or closed // change to boolean?
int speedReedCounter = 0; // ??
// CADENCE VARIABLES
////////////////////
long cadenceTimer = 0; // time between one full rotation (in ms)
long cadenceNumberSamples = 0; // total of revolutions made by the front wheel
float cadenceSamplesSum = 0.00; // sum of all the speeds collected
float cadence = 0.00; // actual cadence
float avgCadence = 0.00; // average cadence of the ride
float topCadence = 0.00; // top cadence fo the ride
int cadenceReedVal = 0; // stores if the switch is open or closed // change to boolean?
int cadenceReedCounter = 0; // ??
// TEMPERATURE
//////////////
float temperature = 0.00; // stores the temperature
float maxTemp = 0.00; // stores the maximum temperature of the ride
float minTemp = 100.00; // stores the minimum temperature of the ride
float avgTemp = 0.00; // stores the average temp of the ride
float tempSum = 0.00; // sum of all the temperature reads
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// SETUP
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
// BAROMETER
// initializate the BMP085
if (!bmp.begin())
{
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
for (int i = 0; i < altSamplesAmount; i++)
{
altSamples[i] = bmp.readAltitude(101490);
}
minAltitude = bmp.readAltitude(101490); // initiates withe the actual altitude
lastAltitude = bmp.readAltitude(101490); // initiates withe the actual altitude
speedReedCounter = maxReedCounter; // ?
cadenceReedCounter = maxReedCounter; // ?
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
// speed input
pinMode(speedReed, INPUT);
// cadence input
pinMode(cadenceReed, INPUT);
// pushbutton input:
pinMode(buttonPin, INPUT);
// LCD
// init done
display.begin();
// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(50);
// iniciates the array
for (int i = 0; i < graphSteps; i++)
{
speedGraph[i] = 0;
}
// SD
/*
if (!SD.begin(4))
{
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
*/
/*
TODO
1 - search if there is a filename that starts with 01
2 - if it finds a filename that starts with 01, find if there is a filename that starts with 02,03,04...
3 - after find the last log add 1 to logCount and start a new log with this number
REF
http://arduino.cc/forum/index.php?topic=108264.0
http://arduino.cc/forum/index.php?PHPSESSID=a96c1ff6fa88ecd4d0d0094696a1edeb&/topic,105997.0.html
* - http://www.ladyada.net/make/logshield/lighttempwalkthru.html
TEST
*/
/*
// while the filename exists...
while(SD.exists(logName))
{
logCount += 1; // adds 1 to the counter
logName[5] = logCount / 10 + '0';
logName[6] = logCount % 10 + '0';
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open(logName, FILE_WRITE);
*/
/*
// create a new file
for (uint8_t i = 0; i < 100; i++)
{
logName[5] = i/10 + '0';
logName[6] = i%10 + '0';
if (!SD.exists(logName))
{
// only open a new file if it doesn't exist
myFile = SD.open(logName, FILE_WRITE);
break; // leave the loop!
}
}
// if the file opened okay, write to it
if (myFile)
{
//Serial.print("Writing to log...");
myFile.print("speed; avgSpeed; rotations S; cadence; avgCadence; rotations C; rideTime; movingTime; temperature;");
myFile.println();
// close the file:
myFile.close();
} */
// WEIGHT
// convert Kg to Lbs
weight = weight * 2.20462262184877580723;
// TIMER SETUP - the timer interrupt allows precise timed measurements of the reed switch
// for more info about configuration of arduino timers see http://arduino.cc/playground/Code/Timer1
cli(); // stop interrupts
// set timer1 interrupt at 1kHz
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0;
// set timer count for 1khz increments
OCR1A = 1999; // = (1/1000) / ((1/(16*10^6))*8) - 1
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS11 bit for 8 prescaler
TCCR1B |= (1 << CS11);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei(); //allow interrupts
//END TIMER SETUP
Serial.begin(9600);
}// setup end
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// TIMER
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Interrupt at freq of 1000 Hz to measure reed switch
ISR(TIMER1_COMPA_vect)
{
//SPEED
///////
// get val of A0
speedReedVal = digitalRead(speedReed);
// if reed switch is closed
if (speedReedVal)
{
//min time between pulses has passed
if (speedReedCounter == 0)
{
// min time between pulses has passed
kph = (36*float(circumference))/float(speedTimer); // calculate kilometers per hour
// reset speedTimer
speedTimer = 0;
// reset speedReedCounter
speedReedCounter = maxReedCounter;
// increase number of samples by 1 - number of wheel rotations ajust the debouncer??
speedNumberSamples++;
// starts the chronometer
rideStarted = true;
// the wheel is spinning
moving = true;
}
else
{
if (speedReedCounter > 0)
{
// don't let speedReedCounter go negative
speedReedCounter -= 1; // decrement speedReedCounter
}
}
}
else
{
// if reed switch is open
if (speedReedCounter > 0)
{
// don't let speedReedCounter go negative
speedReedCounter -= 1; // decrement speedReedCounter
}
}
if (speedTimer > 2000)
{
// if no new pulses from reed switch- tire is still, set kmh to 0
kph = 0;
// the bike is not moving
moving = false;
}
else
{
speedTimer += 1; // increment speedTimer
}
// CADENCE
//////////
// get val of A1
cadenceReedVal = digitalRead(cadenceReed);
// if reed switch is if closed
if(cadenceReedVal)
{
//min time between pulses has passed
if (cadenceReedCounter == 0)
{
// calculate rotations per minute
cadence = float(60000)/float(cadenceTimer);
// reset timer
cadenceTimer = 0;
// reset reedCounter
cadenceReedCounter = maxReedCounter;
// increase number of samples by 1
cadenceNumberSamples++;
// starts the chronometer
rideStarted = true;
// the wheel is spinning
moving = true;
}
else
{
if(cadenceReedCounter > 0)
{// don't let cadenceReedCounter go negative
// decrement cadenceReedCounter
cadenceReedCounter -= 1;
}
}
}
// if reed switch is open
else
{
// don't let cadenceReedCounter go negative
if (cadenceReedCounter > 0)
{
// decrement cadenceReedCounter
cadenceReedCounter -= 1;
}
}
if (cadenceTimer > 2000)
{
cadence = 0;
}
else
{
cadenceTimer += 1; // increment timer
}
// TIME
///////
// if the timeCount is == to 1000 (1s)
if(millisCount == 1000)
{
// if the ride started...
if(rideStarted)
{
// increments 1 once a second
rideTime += 1;
}
// if the bike is moving...
if(moving)
{
// increments 1 once a second
movingTime += 1;
}
// reset the counter
millisCount = 0;
}
// increments 1 every cicle
millisCount += 1;
} // end of timer
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// LOOP
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
// BUTTON
/////////
// button debounce
if (millis() - beforeButton > buttonDebounce)
{
if (digitalRead(buttonPin) == HIGH)
{
screen += 1;
}
beforeButton = millis();
}
if(screen > 9)
{
screen = 0;
}
// BAROMETER AVERAGE
if (altSamplesStep < altSamplesAmount)
{
float altSum = 0.0;
// adds the actual altitude readin to the correct position in the array
altSamples[altSamplesStep] = bmp.readAltitude(101490);
// sum all the values to make the average
for (int i = 0; i < altSamplesAmount; i++)
{
altSum += altSamples[i];
Serial.print(i);
Serial.print(" - ");
Serial.println(altSamples[i]);
}
Serial.println();
Serial.println(altSum);
// divided by the number of the samples to get the average
averageAltitude = altSum / altSamplesAmount;
Serial.println();
Serial.println(averageAltitude);
Serial.println();
Serial.println(altSamplesStep);
// add 1 to the step counter
altSamplesStep += 1;
}
// if the step count is in the last position...
if(altSamplesStep == altSamplesAmount)
{
// go to first postion
altSamplesStep = 0;
}
// 1 sec cycle
if (millis() - before1Sec > oneSecCycle)
{
// if the ride started...
if(rideStarted)
{
// adds the actual temperature read to de sum
tempSum += temperature;
// save to log
//saveToLog();
// one more loop
loopCounter += 1;
}
// adds the actual speed to the correct postion in the array
speedGraph[graphPosition] = (int) kph;
// update the array position
graphPosition += 1;
// if the graphPosition is at the end...
if(graphPosition >= graphSteps-1)
{
// runs tru the array changin the position of the values "to the left"
for (int i = 0; i < graphSteps - 1; i++)
{
// current value equals to the next value
speedGraph[i] = speedGraph[i+1];
}
// now the graphPosition is always at the end
graphPosition = graphSteps - 1;
}
// CALORIES
///////////
caloriesBurned = (( (float) age * 0.2017) + (weight * 0.09036) + (heartRate * 0.6309) - 55.0969) * (movingTime / 60) / 4.184;
// DISTANCE
///////////
// Ride distance
rideDistance = circumference * (float) speedNumberSamples / 100000; // calculate distance in Km (1000 m)
// SPEED
////////
// verifies if this speed is the top speed of the ride
if(kph > topSpeed)
{
topSpeed = kph;
}
// average speed
speedSamplesSum += kph; // add the new calculate kph
avgSpeed = speedSamplesSum / (float) movingTime; // calculate average speed
// print kph once a second
//displayKMH();
// CADENCE
//////////
// verifies if this cadence is the top cadence of the ride
if(cadence > topCadence)
{
topCadence = cadence;
}
// average cadence
cadenceSamplesSum += cadence; // add the new calculate cadence
avgCadence = cadenceSamplesSum / (float) movingTime; // calculate average cadence
// print cadence once a second
//displayCadence();
// TEMPERATURE
//////////////
// update the actual temperature
temperature = bmp.readTemperature();
// calulate the avgTemp
avgTemp = tempSum / (float) loopCounter;
// verifies if this is the highest temperature recorded
if(temperature > maxTemp)
{
maxTemp = temperature;
}
// verifies if this is the lowest temperature recorded
if(temperature < minTemp)
{
minTemp = temperature;
}
// print temperatures once a second
//displayTemp();
// display other data
//diplayOhterData();
Serial.println(); // jump to the next line
// ALTITUDE
///////////
// you can get a more precise measurement of altitude
// if you know the current sea level pressure which will
// vary with weather and such. If it is 1015 millibars
// that is equal to 101500 Pascals.
altitude = bmp.readAltitude(101490);
// verifies if this altitude can be summed to the totalAscent
if (averageAltitude > lastAltitude && averageAltitude - lastAltitude > filterAltitude)
{
totalAscent += averageAltitude - lastAltitude;
}
// verifies if this is the highest altitude recorded
if (averageAltitude > maxAltitude)
{
maxAltitude = altitude;
}
// verifies if this is the lowest altitude recorded
if (averageAltitude < minAltitude)
{
minAltitude = averageAltitude;
}
// updates the value of lastAltitude
lastAltitude = averageAltitude;
// LCD SCREENS
//////////////
// screen 0 = speed
if(screen == 0)
{
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.println("1 - speed");
display.println();
display.setTextSize(2);
display.println(kph, 2);
// display everything on LCD
display.display();
}
// screen 1 = avgSpeed
else if(screen == 1)
{
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.println("2 - avgSpeed");
display.println();
display.setTextSize(2);
display.println(avgSpeed, 2);
// display everything on LCD
display.display();
}
// screen 2 = cadence
else if(screen == 2)
{
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.println("3 - RPM");
display.println();
display.setTextSize(2);
display.println(cadence, 2);
// display everything on LCD
display.display();
}
// screen 3 = avgCadence
else if(screen == 3)
{
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.println("4 - avgRPM");
display.println();
display.setTextSize(2);
display.println(avgCadence, 2);
// display everything on LCD
display.display();
}
// screen 4 = temperature
else if(screen == 4)
{
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.println("5 - temp");
display.println();
display.setTextSize(2);
display.println(temperature, 2);
// display everything on LCD
display.display();
}
// screen 5 = avgTemperature
else if(screen == 5)
{
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.println("6 - avgTemp");
display.println();
display.setTextSize(2);
display.println(avgTemp, 2);
// display everything on LCD
display.display();
}
// screen 6 = summary
else if(screen == 6)
{
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.print("speed:");
display.println(kph, 2);
display.print("avgS:");
display.println(avgSpeed, 2);
display.print("rpm:");
display.println(cadence, 1);
display.print("temp:");
display.println(temperature, 2);
display.print("moving:");
display.println(printTime(movingTime));
// display everything on LCD
display.display();
}
// screen 7 = speedGraph
else if(screen == 7)
{
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.print("sGraph:");
display.print(kph, 2);
// show the axis scale?
const int topMargin = 20;
float height = 0.00;
for (int i = 0; i < graphSteps; i++)
{
// map the value to the correct interval in display
height = (int) map(speedGraph[i], 0, topSpeed, 48, topMargin);
// create the line
display.drawLine(i*2, 48, i*2, height, BLACK); // ok
}
// display everything on LCD
display.display();
}
// screen 8 = altitude
else if(screen == 8)
{
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.print ("alt ");
display.print(altitude);
display.println("m");
display.print("asc ");
display.print(totalAscent);
display.println("m");
display.print("avg ");
display.print(averageAltitude);
display.println("m");
// display everything on LCD
display.display();
}
// screen 9 = total ascent
else if(screen == 9)
{
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.println("9 - ascent");
display.println();
display.setTextSize(2);
display.println(totalAscent);
// display everything on LCD
display.display();
}
// isto corre de segundo a segundo...
before1Sec = millis();
}// end of onSecCycle
// clears the display for the next cycle
display.clearDisplay();
}// end of loop
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// METHODS
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// return a readeable format of time
String printTime(long t)
{
String time; // stores the time 0:0:0
char temp[25]; // the calculations converded
float h, m, s; // variables for the time calculation
h = t / 3600; // calculates de hours
m = (t % 3600) / 60; // calculates de minutes
s = t % 60; // calculates de seconds