2016-12-09 20:28:11 +00:00
|
|
|
#include "NerfStatTrakConfig.h"
|
2016-12-04 18:53:43 +00:00
|
|
|
#include "Globals.h"
|
2016-09-24 12:12:19 +00:00
|
|
|
|
2016-12-04 18:53:43 +00:00
|
|
|
#include "StateHandler.h"
|
|
|
|
#include "StateDefault.h"
|
2016-11-29 19:00:47 +00:00
|
|
|
|
|
|
|
|
2016-09-26 21:14:03 +00:00
|
|
|
void setup()
|
2016-09-24 12:12:19 +00:00
|
|
|
{
|
2016-12-04 18:53:43 +00:00
|
|
|
// Configure display
|
2016-09-30 21:14:29 +00:00
|
|
|
display = new SegmentDisplay();
|
2016-12-04 18:53:43 +00:00
|
|
|
|
|
|
|
#ifdef SDUseSPI
|
|
|
|
display->setClockSpeed(NerfClockSpeed);
|
|
|
|
#else
|
|
|
|
display->setClockPin(NerfClockPin);
|
|
|
|
display->setDataPin(NerfDataPin);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
display->setLatchPin(NerfLatchPin);
|
|
|
|
display->setDigits(NerfDigits);
|
2016-09-30 21:14:29 +00:00
|
|
|
display->begin();
|
2016-11-29 19:00:47 +00:00
|
|
|
|
2016-09-24 12:12:19 +00:00
|
|
|
|
2016-12-04 18:53:43 +00:00
|
|
|
// Configure buttons
|
|
|
|
buttonA = new Button();
|
|
|
|
buttonA->init(NerfButtonA);
|
2016-09-24 12:12:19 +00:00
|
|
|
|
2016-12-04 18:53:43 +00:00
|
|
|
buttonB = new Button();
|
|
|
|
buttonB->init(NerfButtonB);
|
2016-11-29 19:00:47 +00:00
|
|
|
|
2016-12-05 22:42:20 +00:00
|
|
|
buttonArmed = new Button();
|
|
|
|
buttonArmed->init(NerfButtonArmed, LOW);
|
|
|
|
|
2016-11-29 19:00:47 +00:00
|
|
|
|
2016-12-04 18:53:43 +00:00
|
|
|
setCurrentState(new DefaultState());
|
|
|
|
}
|
2016-11-29 19:00:47 +00:00
|
|
|
|
|
|
|
|
2016-09-26 21:14:03 +00:00
|
|
|
void loop()
|
2016-09-24 12:12:19 +00:00
|
|
|
{
|
2016-11-27 22:14:17 +00:00
|
|
|
currentTime = millis();
|
2016-09-24 12:12:19 +00:00
|
|
|
|
2016-12-04 18:53:43 +00:00
|
|
|
buttonA->update(currentTime);
|
|
|
|
buttonB->update(currentTime);
|
2016-12-05 22:42:20 +00:00
|
|
|
buttonArmed->update(currentTime);
|
|
|
|
|
|
|
|
// Count the shot no matter which state we're in
|
|
|
|
if (buttonArmed->changed() && !buttonArmed->pressed())
|
|
|
|
shots++;
|
2016-11-29 19:00:47 +00:00
|
|
|
|
2016-12-04 18:53:43 +00:00
|
|
|
currentState->loop();
|
2016-09-24 12:12:19 +00:00
|
|
|
}
|