Stairs/module/src/main.cpp

57 lines
981 B
C++

/*
* Stairs lighting
* Copyright 2017 (c) Mark van Renswoude
*
* https://git.x2software.net/pub/Stairs
*/
#include <Arduino.h>
#include <Wire.h>
#include "global.h"
#include "display.h"
enum struct State: uint8_t
{
WaitingForComm,
Connected
};
State currentState = State::WaitingForComm;
void setup()
{
settings.init();
// Set up I2C devices: the SSD1306 OLED display and PCA9685 LED PWM driver
Wire.begin();
display.init();
ledDriver.setAddress(0x40);
// At 16 Mhz we pick a baud rate with a very acceptable 0.2% error rate
// Source: http://www.robotroom.com/Asynchronous-Serial-Communication-2.html
Serial.begin(76800);
comm.begin();
}
void loop()
{
if (comm.update())
{
// TODO get data
currentState = State::Connected;
}
switch (currentState)
{
case State::WaitingForComm:
display.show(Screen::WaitingForComm);
break;
case State::Connected:
display.show(Screen::ModuleIndex);
break;
}
}