UVControl/src/main.cpp

115 lines
2.3 KiB
C++
Raw Permalink Normal View History

2017-11-27 14:51:32 +00:00
#include <Arduino.h>
2017-11-26 19:22:15 +00:00
#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"
2017-11-26 19:22:15 +00:00
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
2017-11-26 19:22:15 +00:00
ScreenManager* screenManager;
uint32_t currentTime;
2017-11-26 19:22:15 +00:00
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();
2017-11-26 19:22:15 +00:00
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);
2017-11-26 19:22:15 +00:00
lcd.begin(LCDWidth, LCDHeight);
screenManager = new ScreenManager(&lcd, &currentTime);
screenManager->show<MenuScreen>();
2017-11-26 19:22:15 +00:00
Buzzer::startup();
2017-11-26 19:22:15 +00:00
}
int32_t lastPosition = 0;
2017-11-26 19:22:15 +00:00
bool isPressed = false;
void loop()
{
currentTime = millis();
button.update();
2017-11-27 14:51:32 +00:00
int32_t newPosition = encoder.read();
2017-11-26 19:22:15 +00:00
if (abs(newPosition - lastPosition) >= EncoderSensitivity)
{
2017-11-27 14:51:32 +00:00
screenManager->getCurrent()->onEncoder(lastPosition, newPosition);
2017-11-26 19:22:15 +00:00
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>
2017-11-26 19:22:15 +00:00
void setup()
{
pinMode(PinBuzzer, OUTPUT);
lcd.begin(LCDWidth, LCDHeight);
for (uint16_t i = 0 ; i < EEPROM.length() ; i++)
2017-11-26 19:22:15 +00:00
{
EEPROM.update(i, 0);
2017-11-26 19:22:15 +00:00
}
SetExposureTime(DefaultExposureTime);
SetExposureIntensity(DefaultExposureIntensity);
SetBuzzer(BuzzerSetting::CompletedButtonStartup);
SaveSettings();
2017-11-26 19:22:15 +00:00
lcd.setCursor(0, 0);
lcd.print("Memory cleared");
Buzzer::memoryCleared();
2017-11-26 19:22:15 +00:00
}
void loop()
{
}
2017-11-26 19:22:15 +00:00
#endif