diff --git a/controller_teensy/include/definitions.h b/controller_teensy/include/definitions.h index 5008c37..5657a3e 100644 --- a/controller_teensy/include/definitions.h +++ b/controller_teensy/include/definitions.h @@ -121,4 +121,6 @@ bool armed = false; //cmd output values forced to 0 if false #define CURRENT_FILTER_SIZE 60 //latency is about CURRENT_FILTER_SIZE/2*MEASURE_INTERVAL (measure interval is defined by hoverboard controller) #define CURRENT_MEANVALUECOUNT 20 //0<= meanvaluecount < CURRENT_FILTER_SIZE/2. how many values will be used from sorted weight array from the center region. abour double this values reading are used +#define DISPLAYUPDATEPERIOD 100 + #endif \ No newline at end of file diff --git a/controller_teensy/include/display.h b/controller_teensy/include/display.h new file mode 100644 index 0000000..57c13b6 --- /dev/null +++ b/controller_teensy/include/display.h @@ -0,0 +1,38 @@ +#ifndef _DISPLAY_H_ +#define _DISPLAY_H_ + +#include +#include +#include + +#define SCREEN_WIDTH 128 // OLED display width, in pixels +#define SCREEN_HEIGHT 32 // OLED display height, in pixels + +#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) +#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + +void display_init(); +void display_test(); + +void display_init(){ + if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { + Serial.println(F("SSD1306 allocation failed")); + } + display.clearDisplay(); + display.display(); +} + +void display_test(){ + display.clearDisplay(); + display.setTextSize(1); // Normal 1:1 pixel scale + display.setTextColor(SSD1306_WHITE); // Draw white text + display.setCursor(0,0); // Start at top-left corner + display.println(F("Hello Welt")); + display.println(millis()); + display.println(now()); + display.display(); +} + + +#endif \ No newline at end of file diff --git a/controller_teensy/platformio.ini b/controller_teensy/platformio.ini index fc71c50..8c45f07 100644 --- a/controller_teensy/platformio.ini +++ b/controller_teensy/platformio.ini @@ -21,4 +21,5 @@ build_flags = -D USB_SERIAL_HID lib_deps = - robtillaart/ADS1X15@^0.3.9 \ No newline at end of file + robtillaart/ADS1X15@^0.3.9 + adafruit/Adafruit SSD1306@^2.5.7 \ No newline at end of file diff --git a/controller_teensy/src/main.cpp b/controller_teensy/src/main.cpp index f00d356..b1b5e2b 100644 --- a/controller_teensy/src/main.cpp +++ b/controller_teensy/src/main.cpp @@ -1,11 +1,11 @@ #include - #include "definitions.h" #include "structs.h" #include "helpfunctions.h" #include //for teensy rtc #include "comms.h" +#include "display.h" #include "ADS1X15.h" @@ -22,12 +22,6 @@ Tennsy Pin, Pin Name, Connected to - - - - - - void readADS(); void readADC(); void failChecks(); @@ -69,6 +63,9 @@ void setup() pinMode(PIN_LATCH_ENABLE, OUTPUT); digitalWrite(PIN_LATCH_ENABLE,HIGH); //latch on pinMode(PIN_MODE_SWITCH, INPUT_PULLUP); + + + display_init(); delay(2000); Serial.println("Wait finished. Booting.."); @@ -184,7 +181,11 @@ void loop() { leds(); - + static unsigned long last_display_update=0; + if (loopmillis - last_display_update > DISPLAYUPDATEPERIOD) { + last_display_update=loopmillis; + display_test(); + } }