Commit c99c96d6c69a4d0beb60475da369fcebfe53cbbd

Authored by msekar
1 parent d98ad89a

Main RFduino file

Showing 1 changed file with 88 additions and 0 deletions   Show diff stats
main.ino 0 → 100644
... ... @@ -0,0 +1,88 @@
  1 +#include <Bounce2.h>
  2 +#include <gfxfont.h>
  3 +#include <SPI.h>
  4 +#include <Wire.h>
  5 +#include <Adafruit_GFX.h>
  6 +#include <Adafruit_SSD1306.h>
  7 +#include <RFduinoBLE.h>
  8 +
  9 +#define OLED_RESET 4
  10 +#define NUMBUTTONS 3
  11 +
  12 +Adafruit_SSD1306 display(OLED_RESET);
  13 +
  14 +int buttons[NUMBUTTONS]= {2, 3, 4};
  15 +int lap=0;
  16 +bool isRunning=false;
  17 +//unsigned long runningTime[10];
  18 +unsigned long startedTime, finishedTime, elapsedTime;
  19 +int m, s, ms;
  20 +
  21 +Bounce debouncer_tab[NUMBUTTONS]= {Bounce(), Bounce(), Bounce()};
  22 +
  23 +void setup() {
  24 + init_disp();
  25 + blesetup();
  26 + for (int i=0; i < NUMBUTTONS; i++){
  27 + pinMode(buttons[i],INPUT_PULLUP);
  28 + debouncer_tab[i].attach(buttons[i]);
  29 + debouncer_tab[i].interval(50); // interval in ms
  30 + }
  31 +
  32 +}
  33 +
  34 +void loop() {
  35 +
  36 + for (int i=0; i < NUMBUTTONS; i++){
  37 + debouncer_tab[i].update();
  38 + if(debouncer_tab[i].fell()){
  39 + switch(i){
  40 + case 0:
  41 + if(!isRunning){
  42 + startedTime=millis();
  43 + isRunning=true;
  44 + lap++;
  45 + scrolltext(lap);
  46 + Serial.println(" Button 0 is pressed. Starting timer...");
  47 + }
  48 + break;
  49 +
  50 + case 1:
  51 + if(isRunning){
  52 + elapsedTime=elapsedt(startedTime);
  53 + startedTime=millis();
  54 + lap++;
  55 + scrolltext(lap);
  56 + Serial.print(" Button 1 is pressed. Next lap...");
  57 + Serial.print("millis : ");
  58 + Serial.println(elapsedTime);
  59 + sendDataBLE(lap-1, elapsedTime, 0);
  60 + }
  61 + break;
  62 +
  63 + case 2:
  64 + if(isRunning){
  65 + finishedTime=millis();
  66 + elapsedTime=elapsedt(startedTime);
  67 + //elapsed();
  68 + Serial.print(" Button 2 is pressed. Stopping timer... ");
  69 + /*Serial.print(m);
  70 + Serial.print(":");
  71 + Serial.print(s);
  72 + Serial.print(":");
  73 + Serial.println(ms);*/
  74 + Serial.print("millis : ");
  75 + Serial.println(elapsedTime);
  76 + isRunning=false;
  77 + lap=0;
  78 + scrolltext(lap);
  79 +
  80 + }
  81 + break;
  82 +
  83 + }
  84 +
  85 + break;
  86 + }
  87 + }
  88 +}
0 89 \ No newline at end of file
... ...