Compare commits
3 Commits
6b116edbe1
...
v1.1
Author | SHA1 | Date | |
---|---|---|---|
a5a78d442b | |||
d2bf95d944 | |||
a90d6f2188 |
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"functional": "cpp",
|
||||||
|
"cmath": "cpp"
|
||||||
|
}
|
||||||
|
}
|
89
src/SmartCube/cubeDemo.h
Normal file
89
src/SmartCube/cubeDemo.h
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
void interactiveCubeDemo() {
|
||||||
|
const int cx = SCREEN_WIDTH / 2;
|
||||||
|
const int cy = SCREEN_HEIGHT / 2;
|
||||||
|
const int size = 15; // small cube
|
||||||
|
float angle = 0;
|
||||||
|
float speed = 0.05;
|
||||||
|
bool rotating = true;
|
||||||
|
bool showVersion = false;
|
||||||
|
|
||||||
|
bool lastMiddleState = LOW; // Track previous middle button state
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
display.clearDisplay();
|
||||||
|
|
||||||
|
// Read buttons
|
||||||
|
bool leftPressed = digitalRead(PIN_BTN_L) == HIGH;
|
||||||
|
bool rightPressed = digitalRead(PIN_BTN_R) == HIGH;
|
||||||
|
bool middlePressed = digitalRead(PIN_BTN_M) == HIGH;
|
||||||
|
|
||||||
|
// Button actions
|
||||||
|
if (leftPressed) {
|
||||||
|
speed = -0.05;
|
||||||
|
beep(1000);
|
||||||
|
}
|
||||||
|
if (rightPressed) {
|
||||||
|
speed = 0.05;
|
||||||
|
beep(1000);
|
||||||
|
}
|
||||||
|
// Detect middle button press event
|
||||||
|
if (middlePressed && !lastMiddleState) {
|
||||||
|
rotating = !rotating; // toggle rotation
|
||||||
|
showVersion = !rotating; // show image if stopped
|
||||||
|
beep(1000);
|
||||||
|
}
|
||||||
|
lastMiddleState = middlePressed; // update previous state
|
||||||
|
|
||||||
|
// Draw either image or cube
|
||||||
|
if (showVersion) {
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.setCursor(10, 0);
|
||||||
|
display.println("SmartCube");
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setCursor(40, 18);
|
||||||
|
display.println("version");
|
||||||
|
display.setCursor(52, 28);
|
||||||
|
display.println("1.1");
|
||||||
|
display.drawLine(0, 40, SCREEN_WIDTH, 40, WHITE);
|
||||||
|
display.setCursor(0, 44);
|
||||||
|
display.println("by besna_shnita");
|
||||||
|
display.setCursor(18, 55);
|
||||||
|
display.println("tomislav@kopic.hr");
|
||||||
|
} else {
|
||||||
|
if (rotating) angle += speed;
|
||||||
|
|
||||||
|
float cosA = cos(angle);
|
||||||
|
float sinA = sin(angle);
|
||||||
|
|
||||||
|
int x[8], y[8];
|
||||||
|
int vx[8] = {-size, size, size, -size, -size, size, size, -size};
|
||||||
|
int vy[8] = {-size, -size, size, size, -size, -size, size, size};
|
||||||
|
int vz[8] = {-size, -size, -size, -size, size, size, size, size};
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
float x3d = vx[i] * cosA - vz[i] * sinA;
|
||||||
|
float z3d = vx[i] * sinA + vz[i] * cosA;
|
||||||
|
float y3d = vy[i];
|
||||||
|
float factor = 50.0 / (z3d + 50.0);
|
||||||
|
x[i] = cx + x3d * factor;
|
||||||
|
y[i] = cy + y3d * factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int edges[12][2] = {
|
||||||
|
{0,1},{1,2},{2,3},{3,0},
|
||||||
|
{4,5},{5,6},{6,7},{7,4},
|
||||||
|
{0,4},{1,5},{2,6},{3,7}
|
||||||
|
};
|
||||||
|
for (int i = 0; i < 12; i++)
|
||||||
|
display.drawLine(x[edges[i][0]], y[edges[i][0]],
|
||||||
|
x[edges[i][1]], y[edges[i][1]], WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
display.display();
|
||||||
|
delay(50);
|
||||||
|
|
||||||
|
// Exit demo if all buttons pressed
|
||||||
|
if (leftPressed && middlePressed && rightPressed) break;
|
||||||
|
}
|
||||||
|
}
|
@@ -158,26 +158,27 @@ bool cubeWifiManager::tryConnectToSsid(const char* ssid, const char* pass) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup Access Point with DNS and HTTP server
|
|
||||||
void cubeWifiManager::createAP() {
|
void cubeWifiManager::createAP() {
|
||||||
WiFi.softAPdisconnect(true);
|
WiFi.softAPdisconnect(true);
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
WiFi.softAP(_ssid.c_str(), _pass.c_str(), 1, _hidden);
|
WiFi.softAP(_ssid.c_str(), _pass.c_str(), 1, _hidden);
|
||||||
|
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(10, 0);
|
||||||
display.println("AccessPoint created");
|
display.println("Access Point Ready");
|
||||||
display.setCursor(0, 14);
|
display.drawLine(0, 10, 127, 10, WHITE);
|
||||||
display.println("SSID:");
|
display.setCursor(0, 15);
|
||||||
display.setCursor(0, 24);
|
display.print("SSID: ");
|
||||||
display.setTextSize(1);
|
|
||||||
display.println(_ssid.c_str());
|
display.println(_ssid.c_str());
|
||||||
display.setTextSize(1);
|
display.setCursor(0, 28);
|
||||||
display.setCursor(0, 40);
|
|
||||||
display.println("Config portal:");
|
display.println("Config portal:");
|
||||||
display.setCursor(0, 50);
|
display.setCursor(0, 38);
|
||||||
display.print("http://");
|
display.print("http://");
|
||||||
display.println(WiFi.softAPIP().toString());
|
display.println(WiFi.softAPIP().toString());
|
||||||
|
display.drawLine(0, 50, 127, 50, WHITE);
|
||||||
|
display.setCursor(3, 54);
|
||||||
|
display.println("Press button to skip");
|
||||||
|
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
server.reset(new ESP8266WebServer(80));
|
server.reset(new ESP8266WebServer(80));
|
||||||
@@ -195,9 +196,28 @@ void cubeWifiManager::createAP() {
|
|||||||
dnsServer.processNextRequest();
|
dnsServer.processNextRequest();
|
||||||
server->handleClient();
|
server->handleClient();
|
||||||
delay(10);
|
delay(10);
|
||||||
|
|
||||||
|
if (digitalRead(PIN_BTN_L) == HIGH || digitalRead(PIN_BTN_M) == HIGH || digitalRead(PIN_BTN_R) == HIGH) {
|
||||||
|
|
||||||
|
tone(PIN_BUZZER, 1000, 100);
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("Skipping WiFi setup...");
|
||||||
|
display.display();
|
||||||
|
delay(500);
|
||||||
|
break; // exit AP mode loop
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Clean up AP mode and return
|
||||||
|
server->stop();
|
||||||
|
WiFi.softAPdisconnect(true);
|
||||||
|
WiFi.mode(WIFI_STA); // back to station mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Redirect to AP IP if not accessed directly
|
// Redirect to AP IP if not accessed directly
|
||||||
bool cubeWifiManager::redirectToIp() {
|
bool cubeWifiManager::redirectToIp() {
|
||||||
if (server->hostHeader() == WiFi.softAPIP().toString()) {
|
if (server->hostHeader() == WiFi.softAPIP().toString()) {
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#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
|
||||||
|
|
||||||
// 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);
|
||||||
@@ -44,5 +45,6 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
interactiveCubeDemo(); // Run the demo screen animation
|
||||||
cubeButtonHandler(); // Continuously check and handle button actions
|
cubeButtonHandler(); // Continuously check and handle button actions
|
||||||
}
|
}
|
Reference in New Issue
Block a user