/
spaceswimmer
/
perf-source
Обзор
Документация
Войти
/
spaceswimmer
/
perf-source
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PerfSource/PerfSource.ino
182 строки
6 KB
spaceswimmer
master removed sleeping in loop
06 апр 2026, 11:56
06 апр 2026, 11:56
e32908d
Код
Авторство
О чём код?
#include "Config.h" #include "ControlPins.h" #include "Display.h" #include "Potentiometer.h" #include "Schedule.h" #include "WebServer.h" void setup() { Serial.begin(115200); loadConfig(); Serial.println("\n=== Frequency Sweep Controller ==="); // === Инициализация пинов управления === pinMode(CONTROL_PIN_1, OUTPUT); pinMode(CONTROL_PIN_2, OUTPUT); pinMode(BUTTON_PIN, INPUT_PULLUP); pinMode(CONTROL_PIN_3, OUTPUT); setControlPins(false); // === 1. Инициализация OLED === Serial.println("Initializing OLED..."); Wire.begin(8, 9); Wire.setClock(400000); bool oledOK = false; if (display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println("OLED: OK at 0x3C"); oledOK = true; } else if (display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { Serial.println("OLED: OK at 0x3D"); oledOK = true; } else { Serial.println("OLED: FAILED"); } if (oledOK) { display.clearDisplay(); display.drawBitmap(0, 0, bitmap_128x64, 128, 64, SSD1306_WHITE); display.display(); delay(2000); } if (oledOK) { display.clearDisplay(); display.setTextSize(2); display.setTextColor(SSD1306_WHITE); display.setCursor(0, 45); display.print("by Sonica"); display.display(); delay(1500); } // === 2. Инициализация цифрового потенциометра === Serial.println("Initializing digital potentiometer..."); setupDigitalPot(); // === 3. Настройка Wi-Fi === wifiEnabled = false; // === 4. Настройка DNS === // dnsServer.start(53, "*", WiFi.softAPIP()); // === 5. Показываем системный экран === if (oledOK) { displayParametersScreen(); } // === 6. Настройка веб-сервера === // setupWebServer(); // server.begin(); // Serial.println("HTTP server started on port 80"); generateSchedule(frequencyToPot(fMin_display), frequencyToPot(fMax_display)); } void loop() { if (wifiEnabled) { dnsServer.processNextRequest(); } // === Обработка кнопки (длинное нажатие = Wi-Fi, короткое = развёртка) === bool reading = digitalRead(BUTTON_PIN); if (reading != lastButtonState) { lastDebounceTime = millis(); if (reading == LOW) { buttonPressStartTime = millis(); // Start timing when pressed } } if ((millis() - lastDebounceTime) > debounceDelay) { static bool longPressHandled = false; if (reading == LOW) { // Button is being held if (!longPressHandled && (millis() - buttonPressStartTime >= LONG_PRESS_DURATION)) { // Long press detected - toggle Wi-Fi if (wifiEnabled) { disableWiFi(); } else { enableWiFi(); } displayParametersScreen(); longPressHandled = true; } buttonWasPressed = true; } else if (reading == HIGH && buttonWasPressed) { // Button released if (!longPressHandled) { // Short press - toggle sweep if (isRunning) { stopSweep(); } else { startSweep(); } } longPressHandled = false; buttonWasPressed = false; } } lastButtonState = reading; // === Логика развёртки === if (isRunning && scheduleSize > 0) { unsigned long elapsed = millis() - startTime; unsigned long total = tMax * 1000; if (elapsed >= 100) { triggerVoltagePulse("off"); } if (elapsed >= total) { // Развертка завершена - сбрасываем потенциометр на начальное значение isRunning = false; currentProgress = 100.0; // Выключаем пины при завершении развертки setControlPins(false); // Возвращаем потенциометр к начальному значению writePotentiometer(startPotValue); currentPotValue = startPotValue; lastWrittenPotValue = startPotValue; displayParametersScreen(); Serial.print("Sweep completed! Potentiometer reset to start value: "); Serial.println(startPotValue); } else { currentProgress = (float)elapsed / (float)total * 100.0; int index = findCurrentPoint(elapsed); if (index >= 0 && index < scheduleSize) { uint8_t newPotValue = schedule[index].potValue; if (newPotValue != currentPotValue) { currentPotValue = newPotValue; // Записываем новое значение в потенциометр writePotentiometer(currentPotValue); lastWrittenPotValue = currentPotValue; Serial.print("Time: "); Serial.print(elapsed / 1000.0, 1); Serial.print("s, Pot: "); Serial.print(currentPotValue); Serial.print(", Freq: "); Serial.print(potToFrequency(currentPotValue), 1); Serial.println(" Hz"); } } static unsigned long lastDisplayUpdate = 0; if (millis() - lastDisplayUpdate > 100) { lastDisplayUpdate = millis(); displayProgressScreen(); } } } delay(50); }