From ccd012a31483e957f74af3dcc24b7a20f3b730a6 Mon Sep 17 00:00:00 2001 From: CodeCrafter912 Date: Sat, 7 Jul 2018 19:27:47 +0200 Subject: [PATCH] updated display to a faster lib --- speedclock.h | 1 + speedclock.ino | 41 +++++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/speedclock.h b/speedclock.h index 07d099a..1e41f59 100644 --- a/speedclock.h +++ b/speedclock.h @@ -50,6 +50,7 @@ typedef struct transcv_struct{ #define RUN_LED_ON HIGH #define RUN_LED_OFF LOW +#define DISPLAY_I2C_ADDRESS 0x3C //Adress of the Display typedef enum {TIMER_INIT = 0, TIMER_READY, TIMER_STARTED, TIMER_RUNNING , TIMER_CANCELLED, TIMER_STOPPED, TIMER_TIMEDOUT, TIMER_FAIL, TIMER_WAIT} timer_state_e; diff --git a/speedclock.ino b/speedclock.ino index c2a4b6d..6259df3 100644 --- a/speedclock.ino +++ b/speedclock.ino @@ -1,16 +1,15 @@ #include #include //#include "fonts.h" -#include +#include +#include "SSD1306Ascii.h" +#include "SSD1306AsciiWire.h" #include "RF24.h" #include "speedclock.h" #include "pitch.h" // internal defines for the OLED display ... -U8G2_SSD1306_128X64_NONAME_1_SW_I2C display(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display -//U8G2_SSD1306_128X64_NONAME_1_HW_I2C display(U8G2_R0,/* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display - - +SSD1306AsciiWire display; /****************** User Config for NRF24***************************/ /*** Set this radio as radio number RADIO0 or RADIO1 ***/ radio_type_e stationNumber = BASESTATION; //---> TOPSTATION has the button connected, BASESTATION is the default ... @@ -92,9 +91,12 @@ void setup(){ radio_data.topstationtime = millis(); // set the current milli second count radio_data.topbuttonpressedtime = 0; // set the time the button was pressed last time to 0 - //initialise OLED and display Welcome Message ... - display.begin(); + //initialise Wire and OLED + Wire.begin(); + Wire.setClock(400000L); + display.begin(&Adafruit128x64, DISPLAY_I2C_ADDRESS); + display.clear(); } void loop(void) { @@ -356,16 +358,13 @@ void update_screen(timer_state_e timer_state){ top_line.toCharArray(string_to_char, sizeof(string_to_char)); //Serial.print("DISPLAY: "); //Serial.println(string_to_char); - display.setFontPosCenter(); - display.setFont(u8g2_font_ncenB08_tr); - int xpos = (128 - (display.getStrWidth(string_to_char)))/2 - 10; + display.setFont(System5x7); + //int xpos = (128 - (display.getStrWidth(string_to_char)))/2 - 10; - display.firstPage(); - do { - display.setFont(u8g2_font_ncenB08_tr); - display.setCursor(xpos,ypos); - display.print(string_to_char); - } while ( display.nextPage() ); + display.home(); + display.print("========"); + display.print(string_to_char); + display.println("======="); } } @@ -401,17 +400,16 @@ void startSequence(void) // first tone if(timer_new_state == TIMER_RUNNING){ tone(PIEZO_PIN, STARTSEQ_TON_1_2_FREQUENCY,STARTSEQ_TON_1_2_LENGTH_MS ); - delay(STARTSEQ_TONEPAUSE_MS + STARTSEQ_TON_1_2_LENGTH_MS); + delay(STARTSEQ_TONEPAUSE_MS); } //second tone if(timer_new_state == TIMER_RUNNING){ tone(PIEZO_PIN, STARTSEQ_TON_1_2_FREQUENCY,STARTSEQ_TON_1_2_LENGTH_MS ); - delay(STARTSEQ_TONEPAUSE_MS + STARTSEQ_TON_1_2_LENGTH_MS ); + delay(STARTSEQ_TONEPAUSE_MS); } //third tone if(timer_new_state == TIMER_RUNNING){ tone(PIEZO_PIN, STARTSEQ_TON_3_FREQUENCY,STARTSEQ_TON_3_LENGTH_MS ); - delay(STARTSEQ_TON_3_LENGTH_MS); } } @@ -432,13 +430,12 @@ void false_start_isr(void) // this will save the time when the runner is really started Serial.println("** Interrupt service routine started: false_start_ISR **"); runner_start_time = millis(); - if(timer_state == TIMER_STARTED){ - Serial.println("** Interrupt service routine set timer_new_state to TIMER_FAIL **"); + if(timer_state == TIMER_STARTED & timer_new_state == TIMER_STARTED){ timer_new_state = TIMER_FAIL; detachInterrupt(digitalPinToInterrupt(FAILSTARTBUTTON_IN)); noTone(PIEZO_PIN); } else { - if(timer_state == TIMER_RUNNING){ + if(timer_state == TIMER_RUNNING | timer_new_state == TIMER_RUNNING ){ // disable this interrupt; detachInterrupt(digitalPinToInterrupt(FAILSTARTBUTTON_IN)); }