This commit is contained in:
interfisch 2022-06-19 15:20:49 +02:00
parent 7e02287892
commit 3301a3eaed
1 changed files with 56 additions and 22 deletions

View File

@ -4,6 +4,10 @@
unsigned long loopmillis; unsigned long loopmillis;
unsigned long last_loopmillis; unsigned long last_loopmillis;
#include <TimeLib.h> //for teensy rtc
time_t getTeensy3Time();
#include <OneButton.h> #include <OneButton.h>
#include <SPI.h> #include <SPI.h>
@ -196,20 +200,44 @@ void display_show_stats();
void display_show_stats2(); void display_show_stats2();
void display_show_stats3(); void display_show_stats3();
void display_show_menu(); void display_show_menu();
time_t getTeensy3Time();
void setup() { void setup() {
Serial.begin(SERIAL_BAUD); //Debug and Program Serial.begin(SERIAL_BAUD); //Debug and Program
Wire.begin();
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Init. ESC"));
display.display(); // Show initial text
esc.init(); esc.init();
display.print(F("Init. SD.. ")); display.display();
Serial.print("Initializing SD card..."); Serial.print("Initializing SD card...");
// see if the card is present and can be initialized: // see if the card is present and can be initialized:
if (!SD.begin(SDCHIPSELECT)) { if (!SD.begin(SDCHIPSELECT)) {
Serial.println("Card failed, or not present"); Serial.println("Card failed, or not present");
display.print(F("Fail!")); display.display();
datalogging=false; //disable logging datalogging=false; //disable logging
delay(1000);
}else{ }else{
Serial.println("Card initialized."); Serial.println("Card initialized.");
display.print(F("OK")); display.display();
} }
analogReadResolution(12); analogReadResolution(12);
@ -233,29 +261,28 @@ void setup() {
}); });
Wire.begin();
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally display.print(F("Init. RTC.. ")); display.display();
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed")); setSyncProvider(getTeensy3Time); //See https://www.pjrc.com/teensy/td_libs_Time.html#teensy3
for(;;); // Don't proceed, loop forever if (timeStatus()!= timeSet) {
Serial.println("Unable to sync with the RTC");
display.println(F("Fail")); display.display();
delay(1000);
} else {
Serial.println("RTC has set the system time");
display.println(F("OK")); display.display();
} }
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 0);
display.println(F("Radio Init"));
display.display(); // Show initial text
display.println(F("Init. NRF24")); display.display();
radio.begin(); radio.begin();
Serial.println("RF24 set rate"); Serial.println("RF24 set rate");
radio.setDataRate( RF24_250KBPS ); //set to slow data rate. default was 1MBPS if (!radio.setDataRate( RF24_250KBPS )){ //set to slow data rate. default was 1MBPS
display.println(F(" Fail Data Rate!")); display.display();
}
//radio.setDataRate( RF24_1MBPS ); //radio.setDataRate( RF24_1MBPS );
//Serial.println("set channel"); //Serial.println("set channel");
@ -272,14 +299,13 @@ void setup() {
Serial.println("start listening"); Serial.println("start listening");
radio.startListening(); radio.startListening();
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE); display.println(F("Finished"));
display.setCursor(10, 0);
display.println(F("Started"));
display.display(); // Show initial text display.display(); // Show initial text
} }
@ -753,6 +779,8 @@ void display_show_stats() {
display.print(F("trip=")); display.print(esc.getTrip(),0); display.print(F(", ")); display.print(esc.getCurrentConsumed(),3); display.println(F("Ah")); display.print(F("trip=")); display.print(esc.getTrip(),0); display.print(F(", ")); display.print(esc.getCurrentConsumed(),3); display.println(F("Ah"));
display.print(F("eff.=")); display.print(esc.getTrip()/esc.getCurrentConsumed(),0); display.println(F("m/Ah")); display.print(F("eff.=")); display.print(esc.getTrip()/esc.getCurrentConsumed(),0); display.println(F("m/Ah"));
display.print(F("RTC=")); display.print(now()); display.println(F(""));
display.print(F("Logging=")); display.print(datalogging); display.println(F(""));
display.display(); // Show initial text display.display(); // Show initial text
@ -838,3 +866,9 @@ void display_show_menu() {
display.display(); // Show initial text display.display(); // Show initial text
} }
time_t getTeensy3Time()
{
return Teensy3Clock.get();
}