UVControl/src/main.cpp

115 lines
2.3 KiB
C++

#include <Arduino.h>
#include <Bounce2.h>
#include <Encoder.h>
#include <LiquidCrystal.h>
#include "config.h"
#include "screen.h"
#include "screen/menu.h"
#include "buzzer.h"
#include "state.h"
LiquidCrystal lcd(PinLCDRS, PinLCDEN, PinLCDDB4, PinLCDDB5, PinLCDDB6, PinLCDDB7);
// Before uploading the sketch, upload it once with ResetEEPROM defined to
// write the default values to the EEPROM
//#define ResetEEPROM
#ifndef ResetEEPROM
ScreenManager* screenManager;
uint32_t currentTime;
Encoder encoder(PinEncoderData, PinEncoderClock);
Bounce button = Bounce();
void setup()
{
pinMode(PinButton, INPUT_PULLUP);
pinMode(PinBuzzer, OUTPUT);
pinMode(PinLED, OUTPUT);
button.attach(PinButton);
button.interval(5);
LoadSettings();
lcd.createChar(LCDCharArrowRight, LCDCharArrowRightMap);
lcd.createChar(LCDCharArrowLeft, LCDCharArrowLeftMap);
lcd.createChar(LCDCharArrowRightHollow, LCDCharArrowRightHollowMap);
lcd.createChar(LCDCharArrowLeftHollow, LCDCharArrowLeftHollowMap);
lcd.createChar(LCDCharUpDown, LCDCharUpDownMap);
lcd.createChar(LCDCharUp, LCDCharUpMap);
lcd.createChar(LCDCharDown, LCDCharDownMap);
lcd.begin(LCDWidth, LCDHeight);
screenManager = new ScreenManager(&lcd, &currentTime);
screenManager->show<MenuScreen>();
Buzzer::startup();
}
int32_t lastPosition = 0;
bool isPressed = false;
void loop()
{
currentTime = millis();
button.update();
int32_t newPosition = encoder.read();
if (abs(newPosition - lastPosition) >= EncoderSensitivity)
{
screenManager->getCurrent()->onEncoder(lastPosition, newPosition);
lastPosition = newPosition;
}
if (button.read() == LOW)
{
if (!isPressed)
{
screenManager->getCurrent()->onButton();
isPressed = true;
}
}
else if (isPressed)
isPressed = false;
screenManager->getCurrent()->onTick();
}
#else
#include <EEPROM.h>
void setup()
{
pinMode(PinBuzzer, OUTPUT);
lcd.begin(LCDWidth, LCDHeight);
for (uint16_t i = 0 ; i < EEPROM.length() ; i++)
{
EEPROM.update(i, 0);
}
SetExposureTime(DefaultExposureTime);
SetExposureIntensity(DefaultExposureIntensity);
SetBuzzer(BuzzerSetting::CompletedButtonStartup);
SaveSettings();
lcd.setCursor(0, 0);
lcd.print("Memory cleared");
Buzzer::memoryCleared();
}
void loop()
{
}
#endif