c99c96d6
msekar
Main RFduino file
|
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
|
#include <Bounce2.h>
#include <gfxfont.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RFduinoBLE.h>
#define OLED_RESET 4
#define NUMBUTTONS 3
Adafruit_SSD1306 display(OLED_RESET);
int buttons[NUMBUTTONS]= {2, 3, 4};
int lap=0;
bool isRunning=false;
//unsigned long runningTime[10];
unsigned long startedTime, finishedTime, elapsedTime;
int m, s, ms;
Bounce debouncer_tab[NUMBUTTONS]= {Bounce(), Bounce(), Bounce()};
void setup() {
init_disp();
blesetup();
for (int i=0; i < NUMBUTTONS; i++){
pinMode(buttons[i],INPUT_PULLUP);
debouncer_tab[i].attach(buttons[i]);
debouncer_tab[i].interval(50); // interval in ms
}
}
void loop() {
for (int i=0; i < NUMBUTTONS; i++){
debouncer_tab[i].update();
if(debouncer_tab[i].fell()){
switch(i){
case 0:
if(!isRunning){
startedTime=millis();
isRunning=true;
lap++;
scrolltext(lap);
Serial.println(" Button 0 is pressed. Starting timer...");
}
break;
case 1:
if(isRunning){
elapsedTime=elapsedt(startedTime);
startedTime=millis();
lap++;
scrolltext(lap);
Serial.print(" Button 1 is pressed. Next lap...");
Serial.print("millis : ");
Serial.println(elapsedTime);
sendDataBLE(lap-1, elapsedTime, 0);
}
break;
case 2:
if(isRunning){
finishedTime=millis();
elapsedTime=elapsedt(startedTime);
//elapsed();
Serial.print(" Button 2 is pressed. Stopping timer... ");
/*Serial.print(m);
Serial.print(":");
Serial.print(s);
Serial.print(":");
Serial.println(ms);*/
Serial.print("millis : ");
Serial.println(elapsedTime);
isRunning=false;
lap=0;
scrolltext(lap);
}
break;
}
break;
}
}
}
|