chore: add project files
Diff
.travis.yml | 67 +++++++++++++++++++-
lib/readme.txt | 41 ++++++++++++-
platformio.ini | 14 ++++-
src/main.cpp | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 327 insertions(+)
@@ -0,0 +1,67 @@
@@ -0,0 +1,41 @@
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.
The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".
For example, see how can be organized `Foo` and `Bar` libraries:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) http://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- readme.txt --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
Then in `src/main.c` you should use:
#include <Foo.h>
#include <Bar.h>
// rest H/C/CPP code
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
More information about PlatformIO Library Dependency Finder
- http://docs.platformio.org/page/librarymanager/ldf.html
@@ -0,0 +1,14 @@
[env:uno]
platform = atmelavr
board = uno
framework = arduino
@@ -0,0 +1,205 @@
#include <Arduino.h>
#include <CountUpDownTimer.h>
const int BUTTON_START_PIN = 2; const int LED_START_BUTTON_PIN = 3; int startButtonState = 0;
const int BUTTON_STOP_PIN = 4; const int LED_STOP_BUTTON_PIN = 5; int stopButtonState = 0;
const int RELAY_LAMP_PIN = 6;
const int SHIFT_DATA = 11; const int SHIFT_CLK = 12; const int SHIFT_LATCH = 8;
byte digits[10] = { 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90 };
const int STATE_STANDBY = 0; const int STATE_COUNTDOWN = 1; const int STATE_RUNNING = 2; int state = STATE_STANDBY;
const int RUNTIME_COUNTDOWN = 8; const int RUNTIME_RUNNING = 20; CountUpDownTimer timer(DOWN);
void initButtons()
{
pinMode(BUTTON_START_PIN, INPUT);
pinMode(BUTTON_STOP_PIN, INPUT);
pinMode(LED_START_BUTTON_PIN, OUTPUT);
pinMode(LED_STOP_BUTTON_PIN, OUTPUT);
digitalWrite(LED_START_BUTTON_PIN, HIGH);
digitalWrite(LED_STOP_BUTTON_PIN, LOW);
}
void initDisplay()
{
pinMode(SHIFT_LATCH, OUTPUT);
pinMode(SHIFT_CLK, OUTPUT);
pinMode(SHIFT_DATA, OUTPUT);
}
void initRelays()
{
pinMode(RELAY_LAMP_PIN, OUTPUT);
digitalWrite(RELAY_LAMP_PIN, LOW);
}
void updateDisplay(int value)
{
* more digits
int firstDigit = value / 10;
int secondDigit = value % 10;
digitalWrite(SHIFT_LATCH, LOW);
shiftOut(SHIFT_DATA, SHIFT_CLK, MSBFIRST, digits[secondDigit]);
shiftOut(SHIFT_DATA, SHIFT_CLK, MSBFIRST, digits[firstDigit]);
digitalWrite(SHIFT_LATCH, HIGH);
}
void setup()
{
* starting.
initRelays();
initButtons();
initDisplay();
updateDisplay(00);
}
void loop()
{
bool timerTick = timer.Timer();
if (timer.TimeHasChanged())
{
unsigned long timerValue = timer.ShowSeconds();
updateDisplay(timerValue);
}
if (state == STATE_STANDBY)
{
startButtonState = digitalRead(BUTTON_START_PIN);
if (startButtonState == HIGH)
{
* state
delay(50);
digitalWrite(LED_START_BUTTON_PIN, LOW);
digitalWrite(LED_STOP_BUTTON_PIN, HIGH);
state = STATE_COUNTDOWN;
timer.SetTimer(0, 0, RUNTIME_COUNTDOWN);
timer.StartTimer();
}
}
if ((state == STATE_COUNTDOWN ||
state == STATE_RUNNING) && timerTick)
{
stopButtonState = digitalRead(BUTTON_STOP_PIN);
if (stopButtonState == HIGH)
{
digitalWrite(RELAY_LAMP_PIN, LOW);
digitalWrite(LED_START_BUTTON_PIN, HIGH);
digitalWrite(LED_STOP_BUTTON_PIN, LOW);
state = STATE_STANDBY;
timer.StopTimer();
updateDisplay(00);
* state
delay(50); }
}
* update the state machine accordingly.
if (timer.ShowHours() == 0 && timer.ShowMinutes() == 0 &&
timer.ShowSeconds() == 0)
{
if (state == STATE_COUNTDOWN)
{
digitalWrite(RELAY_LAMP_PIN, HIGH);
state = STATE_RUNNING;
timer.SetTimer(0, 0, RUNTIME_RUNNING);
timer.StartTimer();
}
else if (state == STATE_RUNNING)
{
digitalWrite(RELAY_LAMP_PIN, LOW);
digitalWrite(LED_START_BUTTON_PIN, HIGH);
digitalWrite(LED_STOP_BUTTON_PIN, LOW);
state = STATE_STANDBY;
}
}
}