Created
July 20, 2025 00:12
-
-
Save zr0n/506cd2ff64ef1254eb8e385aa16925fd to your computer and use it in GitHub Desktop.
Codigo para tornozeleira eletronica usando M5Stick C como tornozeleira e qualquer dispositivo esp32 como server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <WiFi.h> | |
| #include <M5StickC.h> | |
| #include <Arduino.h> | |
| #define WIFI_SSID "Tornozeleira" | |
| #define WIFI_PASS "DontHackMeB0y" | |
| #define BUZZER_PIN 26 | |
| bool isConnected = false; | |
| unsigned long lastBlink = 0; | |
| bool ledState = false; | |
| unsigned long lastReconnectAttempt = 0; | |
| void beepAlert() { | |
| tone(BUZZER_PIN, 2000, 500); | |
| delay(500); | |
| noTone(BUZZER_PIN); | |
| } | |
| void connectToWiFi() { | |
| Serial.println("Tentando conectar ao Wi-Fi..."); | |
| WiFi.begin(WIFI_SSID, WIFI_PASS); | |
| int retries = 0; | |
| while (WiFi.status() != WL_CONNECTED && retries < 3) { | |
| delay(500); | |
| Serial.print("."); | |
| retries++; | |
| } | |
| if (WiFi.status() == WL_CONNECTED) { | |
| Serial.println("\nConectado com sucesso!"); | |
| Serial.print("IP: "); | |
| Serial.println(WiFi.localIP()); | |
| } else { | |
| Serial.println("\nFalha na conexão."); | |
| } | |
| } | |
| void setup() { | |
| M5.begin(); | |
| Serial.begin(115200); | |
| delay(1000); | |
| pinMode(BUZZER_PIN, OUTPUT); | |
| digitalWrite(BUZZER_PIN, LOW); | |
| M5.Lcd.setRotation(3); | |
| M5.Lcd.fillScreen(BLACK); | |
| M5.Lcd.setTextSize(1); | |
| WiFi.mode(WIFI_STA); | |
| WiFi.setSleep(false); // Desativa sleep mode para melhor estabilidade | |
| connectToWiFi(); | |
| } | |
| void loop() { | |
| if (WiFi.status() != WL_CONNECTED) { | |
| if (isConnected) { | |
| Serial.println(">>> Wi-Fi desconectado!"); | |
| isConnected = false; | |
| } | |
| unsigned long now = millis(); | |
| if (now - lastBlink > 500) { | |
| lastBlink = now; | |
| ledState = !ledState; | |
| M5.Lcd.fillScreen(ledState ? RED : BLACK); | |
| M5.Lcd.setCursor(10, 10); | |
| M5.Lcd.println("SEM CONEXAO!"); | |
| beepAlert(); | |
| } | |
| if (millis() - lastReconnectAttempt > 5000) { | |
| lastReconnectAttempt = millis(); | |
| connectToWiFi(); | |
| } | |
| } else { | |
| if (!isConnected) { | |
| Serial.println(">>> Reconectado ao Wi-Fi!"); | |
| isConnected = true; | |
| M5.Lcd.fillScreen(BLACK); | |
| for (int i = 0; i < 3; i++) { | |
| M5.Lcd.fillScreen(GREEN); | |
| beepAlert(); | |
| delay(300); | |
| M5.Lcd.fillScreen(BLACK); | |
| delay(300); | |
| } | |
| } | |
| M5.Lcd.setCursor(5, 5); | |
| M5.Lcd.println("Conectado!"); | |
| M5.Lcd.setCursor(5, 20); | |
| M5.Lcd.print("IP: "); | |
| M5.Lcd.println(WiFi.localIP()); | |
| delay(500); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <WiFi.h> | |
| void setup() { | |
| WiFi.mode(WIFI_AP); | |
| WiFi.softAP("Tornozeleira", "DontHackMeB0y"); | |
| Serial.begin(115200); | |
| Serial.println("Rede criada: Tornozeleira"); | |
| } | |
| void loop() { | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment