Initialer Commit
This commit is contained in:
81
src/main.cpp
Normal file
81
src/main.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_SH110X.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
|
||||
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
|
||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||
#define OLED_RESET -1 // QT-PY / XIAO
|
||||
|
||||
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
int VoltPin=A1;
|
||||
float Spannung;
|
||||
float R1=30000;
|
||||
float R2=7500;
|
||||
float Vout;
|
||||
float Vin;
|
||||
|
||||
const byte address[6] = "00001";
|
||||
|
||||
void Startbildschirm(){
|
||||
display.clearDisplay(); //Display löschen
|
||||
display.setTextColor(SH110X_WHITE); //Textfarbe
|
||||
display.setTextSize(2); //Textgröße
|
||||
display.setCursor(25,5);
|
||||
display.print("Battery");
|
||||
display.setCursor(35,35);
|
||||
display.print("Guard");
|
||||
display.display();
|
||||
}
|
||||
|
||||
void Anzeige(){
|
||||
display.clearDisplay(); //Display löschen
|
||||
display.setTextColor(SH110X_WHITE); //Textfarbe
|
||||
display.setTextSize(2); //Textgröße
|
||||
display.setCursor(20,5);
|
||||
display.print("Voltage:");
|
||||
display.setCursor(30,35);
|
||||
display.print(Vin);
|
||||
display.setCursor(100,35);
|
||||
display.print("V");
|
||||
display.display();
|
||||
}
|
||||
|
||||
void Anzeige2(){
|
||||
display.clearDisplay(); //Display löschen
|
||||
display.setTextColor(SH110X_WHITE); //Textfarbe
|
||||
display.setTextSize(2); //Textgröße
|
||||
display.setCursor(20,5);
|
||||
display.print("Battery");
|
||||
display.setCursor(35,35);
|
||||
display.print("low!");
|
||||
display.display();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
Wire.begin(); //SDA -> A4, CLK -> A5
|
||||
display.begin(i2c_Address, true);
|
||||
Startbildschirm();
|
||||
delay(5000);
|
||||
|
||||
pinMode(VoltPin,INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Spannung=analogRead(VoltPin);
|
||||
Vout=Spannung*5/1024;
|
||||
Vin=Vout/(R2/(R1+R2));
|
||||
|
||||
while(Vin>10.5){
|
||||
Spannung=analogRead(VoltPin);
|
||||
Vout=Spannung*5/1024;
|
||||
Vin=Vout/(R2/(R1+R2));
|
||||
Anzeige();
|
||||
delay(1000);
|
||||
}
|
||||
Anzeige2();
|
||||
}
|
||||
Reference in New Issue
Block a user