#include #include const char* ssid = "Dekoder_Morse"; const char* password = "TajneHaslo123"; const char* serverIP = "192.168.4.1"; const int PIN_INPUT = 5; // D1 const int PIN_SUBMIT = 4; // D2 const int PIN_LED = 14; // D5 const int PIN_BUZZER = 12; // D6 (NOWE) const int DEBOUNCE_TIME = 30; const int DOT_DASH_THRESHOLD = 250; unsigned long pressStartTime = 0; bool isInputPressed = false; bool lastSubmitState = HIGH; String aktualnyMorse = ""; String aktualnaLitera = "-"; const int DICT_SIZE = 26; const String morseCodes[DICT_SIZE] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." }; const char letters[DICT_SIZE] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; void sendToServer(String param, String value) { if (WiFi.status() == WL_CONNECTED) { WiFiClient client; HTTPClient http; String url = "http://" + String(serverIP) + "/update2?" + param + "=" + value; http.begin(client, url); http.GET(); http.end(); } } void setup() { Serial.begin(115200); pinMode(PIN_INPUT, INPUT_PULLUP); pinMode(PIN_SUBMIT, INPUT_PULLUP); pinMode(PIN_LED, OUTPUT); pinMode(PIN_BUZZER, OUTPUT); // Inicjalizacja buzzera WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } } void loop() { bool currentInputState = digitalRead(PIN_INPUT); // Lokalna reakcja (dźwięk i LED na drugiej płytce) if (currentInputState == LOW) { digitalWrite(PIN_LED, HIGH); tone(PIN_BUZZER, 800); } else { digitalWrite(PIN_LED, LOW); noTone(PIN_BUZZER); } if (currentInputState == LOW && !isInputPressed) { isInputPressed = true; pressStartTime = millis(); delay(DEBOUNCE_TIME); } else if (currentInputState == HIGH && isInputPressed) { isInputPressed = false; unsigned long pressDuration = millis() - pressStartTime; if (pressDuration > DEBOUNCE_TIME) { if (pressDuration < DOT_DASH_THRESHOLD) aktualnyMorse += "."; else aktualnyMorse += "-"; sendToServer("m", aktualnyMorse); } delay(DEBOUNCE_TIME); } bool currentSubmitState = digitalRead(PIN_SUBMIT); if (currentSubmitState == LOW && lastSubmitState == HIGH) { if (aktualnyMorse.length() > 0) { aktualnaLitera = "-"; for (int i = 0; i < DICT_SIZE; i++) { if (morseCodes[i] == aktualnyMorse) { aktualnaLitera = String(letters[i]); break; } } sendToServer("l", aktualnaLitera); aktualnyMorse = ""; } delay(50); } lastSubmitState = currentSubmitState; }