Upgrade to 1.2
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
#define ADC_PIN A0 // ESP8266 ADC pin
|
||||
|
||||
// Tuneable min and max battery voltages
|
||||
float VOLTAGE_MAX = 4.2; // Full battery voltage
|
||||
float VOLTAGE_MIN = 3.0; // Empty battery voltage
|
||||
|
||||
const float R1 = 220000.0; // 220k ohms
|
||||
const float R2 = 56000.0; // 56k ohms
|
||||
const float ADC_MAX = 1023.0; // 10-bit ADC resolution
|
||||
const float V_REF = 1.0; // ESP8266 ADC reference voltage
|
||||
const float V_REF = 3.3; // ESP8266 ADC reference voltage
|
||||
|
||||
float readBatteryVoltage() {
|
||||
int rawADC = analogRead(ADC_PIN);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
void interactiveCubeDemo() {
|
||||
const int cx = SCREEN_WIDTH / 2;
|
||||
const int cy = SCREEN_HEIGHT / 2;
|
||||
const int size = 15; // small cube
|
||||
const int cy = SCREEN_HEIGHT / 2 - 10;
|
||||
const int size = 14; // small cube
|
||||
float angle = 0;
|
||||
float speed = 0.05;
|
||||
bool rotating = true;
|
||||
@@ -53,6 +53,19 @@ void interactiveCubeDemo() {
|
||||
} else {
|
||||
if (rotating) angle += speed;
|
||||
|
||||
float voltage = readBatteryVoltage();
|
||||
int percent = batteryPercentage(voltage);
|
||||
display.setCursor(0, 55);
|
||||
display.print("Battery:");
|
||||
display.setCursor(66, 55);
|
||||
display.print(voltage, 2);
|
||||
display.print("V");
|
||||
display.setCursor(98, 55);
|
||||
display.print("(");
|
||||
display.print(percent);
|
||||
display.print("%");
|
||||
display.print(")");
|
||||
|
||||
float cosA = cos(angle);
|
||||
float sinA = sin(angle);
|
||||
|
||||
|
@@ -8,4 +8,10 @@
|
||||
#define PIN_BTN_L 12 // D6
|
||||
#define PIN_BTN_M 13 // D7
|
||||
#define PIN_BTN_R 14 // D8
|
||||
#define PIN_BUZZER 0 // D3
|
||||
#define PIN_BUZZER 0 // D3
|
||||
|
||||
// Battery measurement
|
||||
#define R1 220000.0 // 220k ohms
|
||||
#define R2 56000.0 // 56k ohms
|
||||
#define VOLTAGE_MAX 4.2 // Full battery voltage
|
||||
#define VOLTAGE_MIN 3.0 // Empty battery voltage
|
15
src/main.cpp
15
src/main.cpp
@@ -1,10 +1,11 @@
|
||||
#include "example_config.h" // Include the configuration header file
|
||||
#include <Arduino.h> // Include the core Arduino library
|
||||
#include <Adafruit_SSD1306.h> // Include the Adafruit library for the SSD1306 OLED display
|
||||
#include "SmartCube/cubeSound.h" // Include custom header for sound functions
|
||||
#include "SmartCube/cubeButtons.h" // Include custom header for button handling functions
|
||||
#include "SmartCube/cubeWifiManager.h" // Include custom header for managing WiFi connections
|
||||
#include "SmartCube/cubeDemo.h" // Remove this if not using demo functions
|
||||
#include "example_config.h" // Include the configuration header file
|
||||
#include <Arduino.h> // Include the core Arduino library
|
||||
#include <Adafruit_SSD1306.h> // Include the Adafruit library for the SSD1306 OLED display
|
||||
#include "SmartCube/cubeSound.h" // Include custom header for sound functions
|
||||
#include "SmartCube/cubeButtons.h" // Include custom header for button handling functions
|
||||
#include "SmartCube/cubeWifiManager.h" // Include custom header for managing WiFi connections
|
||||
#include "SmartCube/cubeBattery.h" // Remove this if not using demo functions
|
||||
#include "SmartCube/cubeDemo.h" // Remove this if not using demo functions
|
||||
|
||||
// Initialize the OLED display with specified width, height, and reset pin
|
||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
|
Reference in New Issue
Block a user