Compare commits
19 Commits
a5a78d442b
...
main
Author | SHA1 | Date | |
---|---|---|---|
55cb9177db | |||
128085056b | |||
9ea3f3c8f9 | |||
a828f10d8b | |||
cca9c19c9f | |||
4802ed0da3 | |||
f7c1039826 | |||
f353063a8d | |||
1606798b21 | |||
cac25b11c2 | |||
3d0700752a | |||
5e22083e38 | |||
53ee2021dc | |||
3b9d4b9d89 | |||
21f31f9664 | |||
da149fbe02 | |||
af8391a286 | |||
5c9f072ed4 | |||
8667f47e51 |
220
Readme.md
@@ -1,8 +1,10 @@
|
|||||||
# SmartCube
|
# SmartCube
|
||||||
|
|
||||||
**SmartCube** is a tiny and customizable desk toy using the ESP8266 D1 Mini.
|
is a compact, customizable desk companion powered by an ESP8266 microcontroller.
|
||||||
Built entirely from cheap, easy-to-find parts, it can connect to Wi-Fi and can be programmed to do just about anything:
|
Built entirely from cheap, easy-to-find parts, it can be programmed for a variety of tasks:
|
||||||
show notifications, display the weather, monitor stuff, show a clock, serve a web site, mine crypto, be a virtual pet or whatever else your caffeine-fueled brain can imagine.
|
show notifications, display the weather, monitor sensors, act as a clock, host a simple web page, serve as a WiFi extender, run small background tasks, or even be a virtual pet
|
||||||
|
|
||||||
|
Whatever you feel like experimenting with!
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -17,51 +19,28 @@ show notifications, display the weather, monitor stuff, show a clock, serve a we
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Demo Code Explanation
|
### Table of Contents
|
||||||
|
|
||||||
This repository contains a basic "Hello, World!" project for the SmartCube.
|
1. [Bill of Materials](#bill-of-materials)
|
||||||
|
2. [3D-Printing the Case](#3d-printing-the-case)
|
||||||
### Getting Started:
|
3. [Assembly Instructions](#assembly-instructions)
|
||||||
|
* [Body](#body)
|
||||||
1. Download and install **[VSCode](https://code.visualstudio.com/)** or **[VSCodium](https://vscodium.com/)**.
|
* [Buttons](#buttons)
|
||||||
2. Install the **[PlatformIO IDE extension](https://platformio.org/platformio-ide)**.
|
* [OLED Display](#oled-display)
|
||||||
3. Clone this repository and open the project folder in VSCode/VSCodium.
|
* [Buzzer](#buzzer)
|
||||||
4. PlatformIO will automatically handle environment setup and dependencies when you open the project.
|
* [Battery Setup](#battery-setup)
|
||||||
|
4. [Schematics](#schematics)
|
||||||
### Project Structure:
|
5. [GPIO Pin Reference Table](#gpio-pin-reference-table)
|
||||||
|
6. [Demo Code Explanation](#demo-code-explanation)
|
||||||
All source code is located in the `src/` directory.
|
* [Getting Started](#getting-started)
|
||||||
You should start by opening **`src/main.cpp`**, which contains the entry point and initialization logic.
|
* [Uploading with PlatformIO](#uploading-with-platformio)
|
||||||
|
* [Project Structure](#project-structure)
|
||||||
### What the Code Does:
|
* [What the Code Does](#what-the-code-does)
|
||||||
|
* [Key Features](#key-features)
|
||||||
This demo handles basic system functionality, including:
|
* [WiFi Management](#wifi-management)
|
||||||
|
* [Button Handling](#button-handling)
|
||||||
* System initialization
|
* [Default Button Actions](#default-button-actions)
|
||||||
* Button input handling
|
7. [Tips and tricks](#tips-and-tricks)
|
||||||
* OLED display output configuration
|
|
||||||
* WiFi management
|
|
||||||
|
|
||||||
### Key Features
|
|
||||||
|
|
||||||
1. **WiFi Management**:
|
|
||||||
- The [cubeWifiManager](https://git.kopic.hr/tomislav/SmartCubeV1/src/branch/main/src/SmartCube/cubeWifiManager.h) class manages WiFi connectivity seamlessly.
|
|
||||||
- If no known WiFi network is available, it starts a configuration portal and creates an access point (AP), allowing users to connect the SmartCube to a network from another WiFi-enabled device.
|
|
||||||
- The OLED display shows the access point details, such as the AP name and IP address, making the setup process very easy.
|
|
||||||
|
|
||||||
2. **Button Handling**:
|
|
||||||
- Buttons are mapped to specific GPIO pins: `PIN_BTN_L` (Left), `PIN_BTN_M` (Middle), and `PIN_BTN_R` (Right).
|
|
||||||
- The [cubeButtonHandler](https://git.kopic.hr/tomislav/SmartCubeV1/src/branch/main/src/SmartCube/cubeButtons.h) function, executed in the [loop()](https://git.kopic.hr/tomislav/SmartCubeV1/src/commit/1cb51f502d92a91c6a83ce6364b434db31bfd864/src/main.cpp#L47), monitors and interprets button presses, differentiating between short and long presses.
|
|
||||||
|
|
||||||
#### Default Button Actions
|
|
||||||
- **Right Button**:
|
|
||||||
- *Short Press*: Turns the OLED display **on** (if previously off).
|
|
||||||
- *Long Press*: Turns the OLED display **off**, helping conserve power.
|
|
||||||
|
|
||||||
- **Left + Middle Buttons (Simultaneous Long Press)**:
|
|
||||||
- Triggers an ESP8266 reboot, effectively restarting the device.
|
|
||||||
|
|
||||||
This is meant to provide a minimal starting point for further development with the SmartCube.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -69,26 +48,44 @@ This is meant to provide a minimal starting point for further development with t
|
|||||||
|
|
||||||
| **Component** | **Quantity** | **Description** | **Notes** |
|
| **Component** | **Quantity** | **Description** | **Notes** |
|
||||||
|---------------------------|--------------|-------------------------------------------|---------------------------------------------|
|
|---------------------------|--------------|-------------------------------------------|---------------------------------------------|
|
||||||
|
| Enclosure | 1 | 3D-printed case | 3D printable STL files are in `hardware/case/` |
|
||||||
| ESP8266 D1 Mini | 1 | Microcontroller module | |
|
| ESP8266 D1 Mini | 1 | Microcontroller module | |
|
||||||
| SSD1306 OLED Display | 1 | 128x64 resolution, I2C interface | |
|
| SSD1306 OLED Display | 1 | 128x64 resolution, I2C interface | |
|
||||||
| 14250 Rechargeable Battery| 1 | Lithium-ion battery | Make sure you get the rechargeable type, most 14250 are not |
|
|
||||||
| TP4056 Module | 1 | Charging and protection circuit | Does not need to have a USB connector |
|
|
||||||
| 6x6 Push Buttons | 3 or 4 | Tactile push buttons | |
|
| 6x6 Push Buttons | 3 or 4 | Tactile push buttons | |
|
||||||
|
| Resistors (10kΩ) | 3 or 4 | Pull-down resistors for buttons | Generally any resistor between 1kΩ and 100kΩ will work |
|
||||||
| 20mm Piezo Buzzer | 1 | Caseless buzzer for audio | |
|
| 20mm Piezo Buzzer | 1 | Caseless buzzer for audio | |
|
||||||
| Resistors (10kΩ) | 3 or 4 | Pull-down resistors for buttons | |
|
|
||||||
| Resistors (220kΩ and 56kΩ)| 1 | Voltage divider | For monitoring the battery charge level |
|
|
||||||
| Wires | Several | Thin wires for connections | I used wires from inside an old ethernet cable |
|
| Wires | Several | Thin wires for connections | I used wires from inside an old ethernet cable |
|
||||||
| Enclosure | 1 | 3D-printed case | 3D printable STL files are in `hardware/case/` |
|
|
||||||
| 2x6mm screw | 8 | Small screws for assembling the case | Does not have to be exactly 6mm long |
|
| 2x6mm screw | 8 | Small screws for assembling the case | Does not have to be exactly 6mm long |
|
||||||
| 2x2mm screw | 4 | Small screws for the front | Mostly for cosmetic purposes |
|
| 2x2mm screw | 4 (Optional) | Small screws for the front | Mostly for cosmetic purposes |
|
||||||
|
| 14250 Rechargeable Battery| 1 (Optional) | Lithium-ion battery | Make sure it's rechargeable; most 14250 aren't |
|
||||||
|
| TP4056 Module | 1 (Optional) | Charging and protection circuit | USB connector not required |
|
||||||
|
| Resistors (220kΩ and 56kΩ)| 1 (Optional) | Voltage divider for measuring battery level | You can also use 100kΩ and 47kΩ |
|
||||||
|
| Micro Slider Switch (SS-12D00) | 1 (Optional) | On/Off switch | Only needed if installing the battery |
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### 3D-Printing the Case
|
||||||
|
|
||||||
|
The SmartCube case is fully 3D-printable. STL files are included this repository in the `/hardware/case/` directory:
|
||||||
|
|
||||||
|
| **File** | **Description** |
|
||||||
|
| ----------------------------------------- | ------------------------------------------- |
|
||||||
|
| `SmartCube_Body_3_button.stl` | Main cube body with slots for 3 buttons |
|
||||||
|
| `SmartCube_Body_4_button.stl` | Body variant for 4 buttons |
|
||||||
|
| `SmartCube_Front.stl` | Front panel for OLED display |
|
||||||
|
| `SmartCube_Front_No_Holes.stl` | Front panel variant without decorative screw holes |
|
||||||
|
| `SmartCube_Back_Speaker_Side_Hole.stl` | Back panel |
|
||||||
|
| `SmartCube_Back_Speaker_Power_Switch.stl` | Back panel variant with power switch slot |
|
||||||
|
|
||||||
|
* Use PLA or PETG
|
||||||
|
* 0.2 mm layer hight is more than enough, you can print finer if you want to.
|
||||||
|
* Supports may be required depending on your printer
|
||||||
|
|
||||||
## Assembly Instructions
|
## Assembly Instructions
|
||||||
---
|
---
|
||||||
1. **Body**
|
### Body
|
||||||
|
|
||||||
Push the ESP8266 microcontroller in the ledge on the bottom [the cube body](https://git.kopic.hr/tomislav/SmartCubeV1/raw/branch/main/hardware/case/SmartCube_Body_3_button.stl), it should 'click in' with the USB-C port facing the hole.
|
Push the ESP8266 microcontroller in the ledge on the bottom [the cube body](https://git.kopic.hr/tomislav/SmartCubeV1/raw/branch/main/hardware/case/SmartCube_Body_3_button.stl), it should 'click in' with the USB-C port facing the hole.
|
||||||
|
|
||||||
@@ -102,7 +99,7 @@ Body with 3 or 4 button slots is available in the `hardware/case/`
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
2. **Buttons**
|
### Buttons
|
||||||
|
|
||||||
At this step, glue the buttons into the top slots and solder resistors to their outputs. You can connect the resistor outputs together, and don't forget to attach an extra wire to the button inputs, this will later be used to connect them to the 3.3V line.
|
At this step, glue the buttons into the top slots and solder resistors to their outputs. You can connect the resistor outputs together, and don't forget to attach an extra wire to the button inputs, this will later be used to connect them to the 3.3V line.
|
||||||
|
|
||||||
@@ -122,7 +119,7 @@ Finally, solder the GND wire to the resistor outputs and connect 3.3V to the but
|
|||||||

|

|
||||||
|
|
||||||
---
|
---
|
||||||
3. **OLED Display**
|
### OLED Display
|
||||||
|
|
||||||
Screw in the 2x2mm screws and hot glue the SSD1306 to the [front part of the cube](https://git.kopic.hr/tomislav/SmartCubeV1/raw/branch/main/hardware/case/SmartCube_Front.stl) solder the 4 wires to the OLED display, make sure you have some extra length, 4-5cm should be more than enough
|
Screw in the 2x2mm screws and hot glue the SSD1306 to the [front part of the cube](https://git.kopic.hr/tomislav/SmartCubeV1/raw/branch/main/hardware/case/SmartCube_Front.stl) solder the 4 wires to the OLED display, make sure you have some extra length, 4-5cm should be more than enough
|
||||||
|
|
||||||
@@ -139,7 +136,7 @@ The OLED display must be connected via I2C on pins:
|
|||||||

|

|
||||||
|
|
||||||
---
|
---
|
||||||
4. **Buzzer**
|
### Buzzer
|
||||||
|
|
||||||
Glue in the buzzer to the [back part of the cube](https://git.kopic.hr/tomislav/SmartCubeV1/raw/branch/main/hardware/case/SmartCube_Back_Speaker_Side_Hole.stl) with superglue
|
Glue in the buzzer to the [back part of the cube](https://git.kopic.hr/tomislav/SmartCubeV1/raw/branch/main/hardware/case/SmartCube_Back_Speaker_Side_Hole.stl) with superglue
|
||||||
|
|
||||||
@@ -150,11 +147,14 @@ As defined in the [example config](https://git.kopic.hr/tomislav/SmartCubeV1/src
|
|||||||

|

|
||||||
---
|
---
|
||||||
|
|
||||||
**Battery Setup**
|
### Battery Setup
|
||||||
|
|
||||||
The battery is optional. Your SmartCube will work fine when powered via USB; however, adding one makes it portable (and much cuter).
|
The battery is optional. Your SmartCube will work fine when powered via USB; however, adding one makes it portable (and much cuter).
|
||||||
|
|
||||||
A single 700 mAh 14250 battery lasts about 24 hours. Keep in mind there's currently no way to manually power the Cube off, it will continue running until the battery is depleted. The TP4056 prevents the cell from being completely drained and should protect it from damage.
|
A single 700 mAh 14250 battery lasts about 24 hours.
|
||||||
|
The TP4056 prevents the cell from being completely drained and should protect it from damage.
|
||||||
|
|
||||||
|
Although it's not shown in any of the pictures or schematics, both the case and the back cover are updated to include a slot for 8.5mm SPDT slider switch(SS-12D00), in case you actually want to have a power switch instead of letting it run until the battery drains.
|
||||||
|
|
||||||
* Solder the 14250 battery to the **TP4056 input pins**.
|
* Solder the 14250 battery to the **TP4056 input pins**.
|
||||||
* Wire the **TP4056 output** to the **3.3V pin** on the D1 Mini to power the device.
|
* Wire the **TP4056 output** to the **3.3V pin** on the D1 Mini to power the device.
|
||||||
@@ -165,6 +165,8 @@ A single 700 mAh 14250 battery lasts about 24 hours. Keep in mind there's curren
|
|||||||
|
|
||||||
This scales the battery voltage safely down for measurement (~0-0.85V).
|
This scales the battery voltage safely down for measurement (~0-0.85V).
|
||||||
|
|
||||||
|
As mentioned in the [Bill of Materials](#bill-of-materials) you can also use 100kΩ and 47kΩ resistors, just be sure to edit [example config](https://git.kopic.hr/tomislav/SmartCubeV1/src/branch/main/src/example_config.h)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
@@ -172,17 +174,103 @@ A single 700 mAh 14250 battery lasts about 24 hours. Keep in mind there's curren
|
|||||||

|

|
||||||
|
|
||||||
---
|
---
|
||||||
|
## Schematics
|
||||||
|
|
||||||
## Notes
|
This is the basic drawing of the circuit without the battery
|
||||||
|
|
||||||
- This is still a work in progress
|

|
||||||
- Everything is pretty tightly packed in there and it's a mess. But it's not as hard to make as it looks.
|
|
||||||
|
This is the complete circuit including the battery and a voltage divider
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### GPIO Pin Reference Table
|
||||||
|
|
||||||
|
| **Component** | **GPIO Pin** | **PlatformIO / Code Macro** |
|
||||||
|
| ----------------------- | ------------ | --------------------------------- |
|
||||||
|
| Left Button | D6 (GPIO12) | `PIN_BTN_L` |
|
||||||
|
| Middle Button | D7 (GPIO13) | `PIN_BTN_M` |
|
||||||
|
| Right Button | D8 (GPIO15) | `PIN_BTN_R` |
|
||||||
|
| Buzzer | D3 (GPIO0) | `PIN_BUZZER` |
|
||||||
|
| OLED SDA | D2 (GPIO4) | `SDA` |
|
||||||
|
| OLED SCL | D1 (GPIO5) | `SCL` |
|
||||||
|
| Battery Voltage Divider | A0 | `A0` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Demo Code Explanation
|
||||||
|
|
||||||
|
This repository contains a basic "Hello, World!" project for the SmartCube.
|
||||||
|
|
||||||
|
### Getting Started:
|
||||||
|
|
||||||
|
1. Download and install **[VSCode](https://code.visualstudio.com/)** or **[VSCodium](https://vscodium.com/)**.
|
||||||
|
2. Install the **[PlatformIO IDE extension](https://platformio.org/platformio-ide)**.
|
||||||
|
3. Clone this repository and open the project folder in VSCode/VSCodium.
|
||||||
|
4. PlatformIO will automatically handle environment setup and dependencies when you open the project.
|
||||||
|
|
||||||
|
### Uploading with PlatformIO
|
||||||
|
|
||||||
|
Once you open this git repository in VSCode and install the PlatformIO extension.
|
||||||
|
|
||||||
|
You can click on the PlatformIO icon on the left sidebar
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
In the PlatformIO panel, expand d1_mini_lite → General to reveal the available tasks.
|
||||||
|
|
||||||
|
Click Build to compile the firmware, and then click Upload to flash it to your SmartCube.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Project Structure:
|
||||||
|
|
||||||
|
All source code is located in the `src/` directory.
|
||||||
|
You should start by opening **`src/main.cpp`**, which contains the entry point and initialization logic.
|
||||||
|
|
||||||
|
### What the Code Does:
|
||||||
|
|
||||||
|
This demo handles basic system functionality, including:
|
||||||
|
|
||||||
|
* System initialization
|
||||||
|
* Button input handling
|
||||||
|
* OLED display output configuration
|
||||||
|
* WiFi management
|
||||||
|
|
||||||
|
### Key Features
|
||||||
|
|
||||||
|
#### WiFi Management
|
||||||
|
- The [cubeWifiManager](https://git.kopic.hr/tomislav/SmartCubeV1/src/branch/main/src/SmartCube/cubeWifiManager.h) class manages WiFi connectivity seamlessly.
|
||||||
|
- If no known WiFi network is available, it starts a configuration portal and creates an access point (AP), allowing users to connect the SmartCube to a network from another WiFi-enabled device.
|
||||||
|
- The OLED display shows the access point details, such as the AP name and IP address, making the setup process very easy.
|
||||||
|
|
||||||
|
#### Button Handling
|
||||||
|
- Buttons are mapped to specific GPIO pins: `PIN_BTN_L` (Left), `PIN_BTN_M` (Middle), and `PIN_BTN_R` (Right).
|
||||||
|
- The [cubeButtonHandler](https://git.kopic.hr/tomislav/SmartCubeV1/src/branch/main/src/SmartCube/cubeButtons.h) function, executed in the [loop()](https://git.kopic.hr/tomislav/SmartCubeV1/src/commit/1cb51f502d92a91c6a83ce6364b434db31bfd864/src/main.cpp#L47), monitors and interprets button presses, differentiating between short and long presses.
|
||||||
|
|
||||||
|
##### Default Button Actions
|
||||||
|
- **Right Button**:
|
||||||
|
- *Long Press*: Turns the OLED display **on** (if previously off).
|
||||||
|
|
||||||
|
- **Left + Middle Buttons (Simultaneous Long Press)**:
|
||||||
|
- Triggers an ESP8266 reboot, effectively restarting the device.
|
||||||
|
|
||||||
|
This is meant to provide a minimal starting point for further development with the SmartCube.
|
||||||
|
|
||||||
|
---
|
||||||
|
## Tips and tricks
|
||||||
|
|
||||||
|
- It's not as hard to make as it looks.
|
||||||
|
- Battery is the trickiest part to fit in, it's best to put in the case last.
|
||||||
|
- Test if everything works before completely closing the case shut.
|
||||||
|
- Make sure all connections are secure and not short-circuited.
|
||||||
|
- Hot glue is your friend, it will add extra protection from short-circuits and keep wires in place.
|
||||||
|
- Everything is pretty tightly packed in there and it can be quite a mess.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
- Ensure all connections are secure and isolated. Hot glue is your friend.
|
|
||||||
- Test the circuit thoroughly before placing and gluing it in the enclosure.
|
|
||||||
- Battery is the trickiest part to fit in, it's best to glue the charging module directly to it and put it in the case last
|
|
||||||
|
|
||||||
For questions or additional details, feel free to reach out! I would love to hear some feedback.
|
For questions or additional details, feel free to reach out! I would love to hear some feedback.
|
||||||
Good luck and have fun :)
|
Good luck and have fun :)
|
||||||
|
BIN
hardware/case/SmartCube_Front_No_Holes.stl
Normal file
BIN
hardware/pictures/IMG_0044.jpg
Normal file
After Width: | Height: | Size: 1.4 MiB |
BIN
hardware/pictures/IMG_0052.jpg
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
hardware/pictures/IMG_0053.jpg
Normal file
After Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 4.2 MiB After Width: | Height: | Size: 1.2 MiB |
BIN
hardware/pictures/platformio1.png
Normal file
After Width: | Height: | Size: 90 KiB |
BIN
hardware/pictures/platformio2.png
Normal file
After Width: | Height: | Size: 124 KiB |
BIN
hardware/schematics/schematic1.png
Normal file
After Width: | Height: | Size: 149 KiB |
BIN
hardware/schematics/schematic2.png
Normal file
After Width: | Height: | Size: 208 KiB |
BIN
hardware/schematics/schematic3.png
Normal file
After Width: | Height: | Size: 228 KiB |
16
src/SmartCube/cubeBattery.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#define ADC_PIN A0 // ESP8266 ADC pin
|
||||||
|
|
||||||
|
const float ADC_MAX = 1023.0; // 10-bit ADC resolution
|
||||||
|
const float V_REF = 3.3; // ESP8266 ADC reference voltage
|
||||||
|
|
||||||
|
float readBatteryVoltage() {
|
||||||
|
int rawADC = analogRead(ADC_PIN);
|
||||||
|
float voltage = (rawADC / ADC_MAX) * V_REF;
|
||||||
|
return voltage * (R1 + R2) / R2; // Scale to actual battery voltage
|
||||||
|
}
|
||||||
|
|
||||||
|
int batteryPercentage(float voltage) {
|
||||||
|
if (voltage >= VOLTAGE_MAX) return 100;
|
||||||
|
if (voltage <= VOLTAGE_MIN) return 0;
|
||||||
|
return (voltage - VOLTAGE_MIN) * 100 / (VOLTAGE_MAX - VOLTAGE_MIN); // Linear mapping
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
void interactiveCubeDemo() {
|
void interactiveCubeDemo() {
|
||||||
const int cx = SCREEN_WIDTH / 2;
|
const int cx = SCREEN_WIDTH / 2;
|
||||||
const int cy = SCREEN_HEIGHT / 2;
|
const int cy = SCREEN_HEIGHT / 2 - 10;
|
||||||
const int size = 15; // small cube
|
const int size = 14; // small cube
|
||||||
float angle = 0;
|
float angle = 0;
|
||||||
float speed = 0.05;
|
float speed = 0.05;
|
||||||
bool rotating = true;
|
bool rotating = true;
|
||||||
@@ -44,7 +44,7 @@ void interactiveCubeDemo() {
|
|||||||
display.setCursor(40, 18);
|
display.setCursor(40, 18);
|
||||||
display.println("version");
|
display.println("version");
|
||||||
display.setCursor(52, 28);
|
display.setCursor(52, 28);
|
||||||
display.println("1.1");
|
display.println("1.2");
|
||||||
display.drawLine(0, 40, SCREEN_WIDTH, 40, WHITE);
|
display.drawLine(0, 40, SCREEN_WIDTH, 40, WHITE);
|
||||||
display.setCursor(0, 44);
|
display.setCursor(0, 44);
|
||||||
display.println("by besna_shnita");
|
display.println("by besna_shnita");
|
||||||
@@ -53,6 +53,19 @@ void interactiveCubeDemo() {
|
|||||||
} else {
|
} else {
|
||||||
if (rotating) angle += speed;
|
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 cosA = cos(angle);
|
||||||
float sinA = sin(angle);
|
float sinA = sin(angle);
|
||||||
|
|
||||||
|
@@ -9,3 +9,9 @@
|
|||||||
#define PIN_BTN_M 13 // D7
|
#define PIN_BTN_M 13 // D7
|
||||||
#define PIN_BTN_R 15 // D8
|
#define PIN_BTN_R 15 // 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
@@ -1,10 +1,11 @@
|
|||||||
#include "example_config.h" // Include the configuration header file
|
#include "example_config.h" // Include the configuration header file
|
||||||
#include <Arduino.h> // Include the core Arduino library
|
#include <Arduino.h> // Include the core Arduino library
|
||||||
#include <Adafruit_SSD1306.h> // Include the Adafruit library for the SSD1306 OLED display
|
#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/cubeSound.h" // Include custom header for sound functions
|
||||||
#include "SmartCube/cubeButtons.h" // Include custom header for button handling 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/cubeWifiManager.h" // Include custom header for managing WiFi connections
|
||||||
#include "SmartCube/cubeDemo.h" // Remove this if not using demo functions
|
#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
|
// Initialize the OLED display with specified width, height, and reset pin
|
||||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|