110 lines
2.1 KiB
C++
110 lines
2.1 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;
|
|
unsigned long 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.begin(LCDWidth, LCDHeight);
|
|
|
|
screenManager = new ScreenManager(&lcd, ¤tTime);
|
|
screenManager->show<MenuScreen>();
|
|
|
|
Buzzer::startup();
|
|
}
|
|
|
|
|
|
long lastPosition = 0;
|
|
bool isPressed = false;
|
|
|
|
|
|
void loop()
|
|
{
|
|
currentTime = millis();
|
|
button.update();
|
|
|
|
long 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
|
|
|
|
void setup()
|
|
{
|
|
pinMode(PinBuzzer, OUTPUT);
|
|
lcd.begin(LCDWidth, LCDHeight);
|
|
|
|
for (int i = 0 ; i < EEPROM.length() ; i++)
|
|
{
|
|
EEPROM.update(i, 0);
|
|
}
|
|
|
|
ExposureTime = DefaultExposureTime;
|
|
ExposureIntensity = DefaultExposureIntensity;
|
|
SaveSettings();
|
|
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("Memory cleared");
|
|
|
|
Buzzer::memoryCleared();
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
}
|
|
|
|
#endif
|