101 lines
1.7 KiB
C++
101 lines
1.7 KiB
C++
#include <Arduino.h>
|
|
#include <Bounce2.h>
|
|
#include <Encoder.h>
|
|
#include <LiquidCrystal.h>
|
|
#include "Config.h"
|
|
#include "ScreenManager.h"
|
|
#include "ScreenSetTime.h"
|
|
#include "Buzzer.h"
|
|
#include "ExposureTimer.h"
|
|
|
|
|
|
LiquidCrystal lcd(PinLCDRS, PinLCDEN, PinLCDDB4, PinLCDDB5, PinLCDDB6, PinLCDDB7);
|
|
|
|
|
|
// Before uploading the sketch, upload it once with ClearEEPROM defined to
|
|
// zero out the memory.
|
|
//#define ClearEEPROM
|
|
#ifndef ClearEEPROM
|
|
|
|
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);
|
|
|
|
ResetExposureTime();
|
|
|
|
lcd.createChar(0, LCDCharArrow);
|
|
lcd.begin(LCDWidth, LCDHeight);
|
|
|
|
screenManager = new ScreenManager(&lcd, ¤tTime);
|
|
screenManager->show<ScreenSetTime>();
|
|
|
|
buzzStartup();
|
|
}
|
|
|
|
|
|
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.write(i, 0);
|
|
}
|
|
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("Memory cleared");
|
|
|
|
buzzMemoryCleared();
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
}
|
|
#endif
|