Support for gun armed detection
First attempt at implementing animation
This commit is contained in:
parent
ba58eb93c0
commit
2e8007d510
|
@ -7,7 +7,7 @@ void Button::init(uint8_t pin, int offState, bool usePullUp)
|
||||||
this->offState = offState;
|
this->offState = offState;
|
||||||
this->lastState = offState;
|
this->lastState = offState;
|
||||||
|
|
||||||
if (offState == HIGH && usePullUp)
|
if (usePullUp)
|
||||||
pinMode(pin, INPUT_PULLUP);
|
pinMode(pin, INPUT_PULLUP);
|
||||||
else
|
else
|
||||||
pinMode(pin, INPUT);
|
pinMode(pin, INPUT);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
SegmentDisplay* display;
|
SegmentDisplay* display;
|
||||||
Button* buttonA;
|
Button* buttonA;
|
||||||
Button* buttonB;
|
Button* buttonB;
|
||||||
|
Button* buttonArmed;
|
||||||
|
|
||||||
uint32_t shots = 0;
|
uint32_t shots = 0;
|
||||||
uint32_t hits = 0;
|
uint32_t hits = 0;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
extern SegmentDisplay* display;
|
extern SegmentDisplay* display;
|
||||||
extern Button* buttonA;
|
extern Button* buttonA;
|
||||||
extern Button* buttonB;
|
extern Button* buttonB;
|
||||||
|
extern Button* buttonArmed;
|
||||||
|
|
||||||
extern uint32_t shots;
|
extern uint32_t shots;
|
||||||
extern uint32_t hits;
|
extern uint32_t hits;
|
||||||
|
|
|
@ -29,6 +29,9 @@ void setup()
|
||||||
buttonB = new Button();
|
buttonB = new Button();
|
||||||
buttonB->init(NerfButtonB);
|
buttonB->init(NerfButtonB);
|
||||||
|
|
||||||
|
buttonArmed = new Button();
|
||||||
|
buttonArmed->init(NerfButtonArmed, LOW);
|
||||||
|
|
||||||
|
|
||||||
setCurrentState(new DefaultState());
|
setCurrentState(new DefaultState());
|
||||||
}
|
}
|
||||||
|
@ -40,6 +43,11 @@ void loop()
|
||||||
|
|
||||||
buttonA->update(currentTime);
|
buttonA->update(currentTime);
|
||||||
buttonB->update(currentTime);
|
buttonB->update(currentTime);
|
||||||
|
buttonArmed->update(currentTime);
|
||||||
|
|
||||||
|
// Count the shot no matter which state we're in
|
||||||
|
if (buttonArmed->changed() && !buttonArmed->pressed())
|
||||||
|
shots++;
|
||||||
|
|
||||||
currentState->loop();
|
currentState->loop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,12 @@ void SegmentDisplay::end()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SegmentDisplay::clear()
|
||||||
|
{
|
||||||
|
writeDisplay(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SegmentDisplay::writeNumber(uint32_t value)
|
void SegmentDisplay::writeNumber(uint32_t value)
|
||||||
{
|
{
|
||||||
#if defined(SDSerialDebug)
|
#if defined(SDSerialDebug)
|
||||||
|
@ -58,7 +64,7 @@ void SegmentDisplay::writeNumber(uint32_t value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SegmentDisplay::writeTextLeft(char* value)
|
void SegmentDisplay::writeTextLeft(char const* value)
|
||||||
{
|
{
|
||||||
#if defined(SDSerialDebug)
|
#if defined(SDSerialDebug)
|
||||||
Serial.print("SegmentDisplay::writeTextLeft: " + value + "\n");
|
Serial.print("SegmentDisplay::writeTextLeft: " + value + "\n");
|
||||||
|
@ -84,15 +90,29 @@ void SegmentDisplay::writeTextLeft(char* value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SegmentDisplay::writeTextCenter(char* value)
|
void SegmentDisplay::writeRaw(char const* value)
|
||||||
{
|
{
|
||||||
// TODO
|
#if defined(SDSerialDebug)
|
||||||
|
Serial.print("SegmentDisplay::writeRaw: " + value + "\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
byte digitMask = 1 << (digits - 1);
|
||||||
|
byte charIndex = 0;
|
||||||
|
|
||||||
|
while (charIndex < digits && value[charIndex] != '\0')
|
||||||
|
{
|
||||||
|
writeDisplay(value[charIndex], digitMask);
|
||||||
|
|
||||||
|
digitMask >>= 1;
|
||||||
|
charIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (charIndex < digits)
|
||||||
void SegmentDisplay::writeTextRight(char* value)
|
|
||||||
{
|
{
|
||||||
// TODO
|
writeDisplay(0, digitMask);
|
||||||
|
digitMask >>= 1;
|
||||||
|
charIndex++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,10 @@ class SegmentDisplay
|
||||||
void begin();
|
void begin();
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
|
void clear();
|
||||||
void writeNumber(uint32_t value);
|
void writeNumber(uint32_t value);
|
||||||
void writeTextLeft(char* value);
|
void writeTextLeft(char const* value);
|
||||||
void writeTextCenter(char* value);
|
void writeRaw(char const* value);
|
||||||
void writeTextRight(char* value);
|
|
||||||
|
|
||||||
byte getDigits() { return digits; }
|
byte getDigits() { return digits; }
|
||||||
void setDigits(byte value) { digits = value; }
|
void setDigits(byte value) { digits = value; }
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define SegmentE 16 // Bottom left
|
#define SegmentE 16 // Bottom left
|
||||||
#define SegmentF 32 // Top left
|
#define SegmentF 32 // Top left
|
||||||
#define SegmentG 64 // Middle
|
#define SegmentG 64 // Middle
|
||||||
|
#define SegmentDP (char)128 // Dot point
|
||||||
|
|
||||||
|
|
||||||
#define ASCIIZero 48
|
#define ASCIIZero 48
|
||||||
|
@ -21,15 +22,13 @@
|
||||||
#define ASCIILowercaseZ 122
|
#define ASCIILowercaseZ 122
|
||||||
|
|
||||||
|
|
||||||
const byte SDNumberSegments[10] PROGMEM =
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* _
|
* _
|
||||||
* | |
|
* | |
|
||||||
* |_|
|
* |_|
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
SegmentA | SegmentB | SegmentC | SegmentD | SegmentE | SegmentF,
|
#define Char0 SegmentA | SegmentB | SegmentC | SegmentD | SegmentE | SegmentF
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -37,7 +36,7 @@ const byte SDNumberSegments[10] PROGMEM =
|
||||||
* |
|
* |
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
SegmentB | SegmentC,
|
#define Char1 SegmentB | SegmentC
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _
|
* _
|
||||||
|
@ -45,7 +44,7 @@ const byte SDNumberSegments[10] PROGMEM =
|
||||||
* |_
|
* |_
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
SegmentA | SegmentB | SegmentD | SegmentE | SegmentG,
|
#define Char2 SegmentA | SegmentB | SegmentD | SegmentE | SegmentG
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _
|
* _
|
||||||
|
@ -53,7 +52,7 @@ const byte SDNumberSegments[10] PROGMEM =
|
||||||
* _|
|
* _|
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
SegmentA | SegmentB | SegmentC | SegmentD | SegmentG,
|
#define Char3 SegmentA | SegmentB | SegmentC | SegmentD | SegmentG
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -61,7 +60,7 @@ const byte SDNumberSegments[10] PROGMEM =
|
||||||
* |
|
* |
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
SegmentB | SegmentC | SegmentF | SegmentG,
|
#define Char4 SegmentB | SegmentC | SegmentF | SegmentG
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _
|
* _
|
||||||
|
@ -69,7 +68,7 @@ const byte SDNumberSegments[10] PROGMEM =
|
||||||
* _|
|
* _|
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
SegmentA | SegmentC | SegmentD | SegmentF | SegmentG,
|
#define Char5 SegmentA | SegmentC | SegmentD | SegmentF | SegmentG
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _
|
* _
|
||||||
|
@ -77,7 +76,7 @@ const byte SDNumberSegments[10] PROGMEM =
|
||||||
* |_|
|
* |_|
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
SegmentA | SegmentC | SegmentD | SegmentE | SegmentF | SegmentG,
|
#define Char6 SegmentA | SegmentC | SegmentD | SegmentE | SegmentF | SegmentG
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _
|
* _
|
||||||
|
@ -85,7 +84,7 @@ const byte SDNumberSegments[10] PROGMEM =
|
||||||
* |
|
* |
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
SegmentA | SegmentB | SegmentC,
|
#define Char7 SegmentA | SegmentB | SegmentC
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _
|
* _
|
||||||
|
@ -93,7 +92,7 @@ const byte SDNumberSegments[10] PROGMEM =
|
||||||
* |_|
|
* |_|
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
SegmentA | SegmentB | SegmentC | SegmentD | SegmentE | SegmentF | SegmentG,
|
#define Char8 SegmentA | SegmentB | SegmentC | SegmentD | SegmentE | SegmentF | SegmentG
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _
|
* _
|
||||||
|
@ -101,220 +100,227 @@ const byte SDNumberSegments[10] PROGMEM =
|
||||||
* _|
|
* _|
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
SegmentA | SegmentB | SegmentC | SegmentD | SegmentF | SegmentG
|
#define Char9 SegmentA | SegmentB | SegmentC | SegmentD | SegmentF | SegmentG
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
* |_|
|
||||||
|
* | |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharA SegmentA | SegmentB | SegmentC | SegmentE | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* |_
|
||||||
|
* |_|
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharB SegmentC | SegmentD | SegmentE | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
* |
|
||||||
|
* |_
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharC SegmentA | SegmentD | SegmentE | SegmentF
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* _|
|
||||||
|
* |_|
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharD SegmentB | SegmentC | SegmentD | SegmentE | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
* |_
|
||||||
|
* |_
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharE SegmentA | SegmentD | SegmentE | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
* |_
|
||||||
|
* |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharF SegmentA | SegmentE | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
* |_|
|
||||||
|
* _|
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharG SegmentA | SegmentB | SegmentC | SegmentD | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* |_|
|
||||||
|
* | |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharH SegmentB | SegmentC | SegmentE | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* |
|
||||||
|
* |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharI SegmentE | SegmentF
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* |
|
||||||
|
* |_|
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharJ SegmentB | SegmentC | SegmentD | SegmentE
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* |_
|
||||||
|
* |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharK SegmentE | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* |
|
||||||
|
* |_
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharL SegmentD | SegmentE | SegmentF
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
*
|
||||||
|
* | |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharM SegmentA | SegmentC | SegmentE
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* _
|
||||||
|
* | |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharN SegmentC | SegmentE | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharO SegmentA | SegmentB | SegmentC | SegmentD | SegmentE | SegmentF
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
* |_|
|
||||||
|
* |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharP SegmentA | SegmentB | SegmentE | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
* |_|
|
||||||
|
* |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharQ SegmentA | SegmentB | SegmentC | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* _
|
||||||
|
* |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharR SegmentE | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
* |_
|
||||||
|
* _|
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharS SegmentA | SegmentC | SegmentD | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* |_
|
||||||
|
* |_
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharT SegmentD | SegmentE | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharU SegmentB | SegmentC | SegmentD | SegmentE | SegmentF
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* |_|
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharV SegmentC | SegmentD | SegmentE
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* | |
|
||||||
|
* _
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharW SegmentB | SegmentD | SegmentF
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* _|
|
||||||
|
* |
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharX SegmentB | SegmentC | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* |_|
|
||||||
|
* _|
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharY SegmentB | SegmentC | SegmentD | SegmentF | SegmentG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _
|
||||||
|
* _|
|
||||||
|
* |_
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
#define CharZ SegmentA | SegmentB | SegmentD | SegmentE | SegmentG
|
||||||
|
|
||||||
|
const byte SDNumberSegments[10] PROGMEM =
|
||||||
|
{
|
||||||
|
Char0, Char1, Char2, Char3, Char4, Char5, Char6, Char7, Char8, Char9
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const byte SDCharacterSegments[26] PROGMEM =
|
const byte SDCharacterSegments[26] PROGMEM =
|
||||||
{
|
{
|
||||||
/**
|
CharA, CharB, CharC, CharD, CharE, CharF, CharG, CharH, CharI, CharJ, CharK, CharL, CharM,
|
||||||
* _
|
CharN, CharO, CharP, CharQ, CharR, CharS, CharT, CharU, CharV, CharW, CharX, CharY, CharZ
|
||||||
* |_|
|
|
||||||
* | |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentB | SegmentC | SegmentE | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* |_
|
|
||||||
* |_|
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentC | SegmentD | SegmentE | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _
|
|
||||||
* |
|
|
||||||
* |_
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentD | SegmentE | SegmentF,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* _|
|
|
||||||
* |_|
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentB | SegmentC | SegmentD | SegmentE | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _
|
|
||||||
* |_
|
|
||||||
* |_
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentD | SegmentE | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _
|
|
||||||
* |_
|
|
||||||
* |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentE | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _
|
|
||||||
* |_|
|
|
||||||
* _|
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentB | SegmentC | SegmentD | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* |_|
|
|
||||||
* | |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentB | SegmentC | SegmentE | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* |
|
|
||||||
* |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentE | SegmentF,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* |
|
|
||||||
* |_|
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentB | SegmentC | SegmentD | SegmentE,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* |_
|
|
||||||
* |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentE | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* |
|
|
||||||
* |_
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentD | SegmentE | SegmentF,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _
|
|
||||||
*
|
|
||||||
* | |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentC | SegmentE,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* _
|
|
||||||
* | |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentC | SegmentE | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _
|
|
||||||
* | |
|
|
||||||
* |_|
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentB | SegmentC | SegmentD | SegmentE | SegmentF,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _
|
|
||||||
* |_|
|
|
||||||
* |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentB | SegmentE | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _
|
|
||||||
* |_|
|
|
||||||
* |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentB | SegmentC | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* _
|
|
||||||
* |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentE | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _
|
|
||||||
* |_
|
|
||||||
* _|
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentC | SegmentD | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* |_
|
|
||||||
* |_
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentD | SegmentE | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* | |
|
|
||||||
* |_|
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentB | SegmentC | SegmentD | SegmentE | SegmentF,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* |_|
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentC | SegmentD | SegmentE,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* | |
|
|
||||||
* _
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentB | SegmentD | SegmentF,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* _|
|
|
||||||
* |
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentB | SegmentC | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* |_|
|
|
||||||
* _|
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentB | SegmentC | SegmentD | SegmentF | SegmentG,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _
|
|
||||||
* _|
|
|
||||||
* |_
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
SegmentA | SegmentB | SegmentD | SegmentE | SegmentG
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,7 +19,7 @@ void DefaultState::loop()
|
||||||
if (buttonA->pressed() && buttonB->pressed())
|
if (buttonA->pressed() && buttonB->pressed())
|
||||||
{
|
{
|
||||||
// A + B
|
// A + B
|
||||||
setCurrentState(new LoseTheGameState());
|
setCurrentState(new UserUnknownState());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ void DefaultState::loop()
|
||||||
// B long
|
// B long
|
||||||
if (buttonB->pressed() && buttonB->pressedMillis(currentTime) > NerfButtonLongPressThreshold)
|
if (buttonB->pressed() && buttonB->pressedMillis(currentTime) > NerfButtonLongPressThreshold)
|
||||||
{
|
{
|
||||||
setCurrentState(new UserUnknownState());
|
setCurrentState(new LoseTheGameState());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
*
|
*
|
||||||
* A: Add hit
|
* A: Add hit
|
||||||
* B short: Toggle between hits and shots and restart state
|
* B short: Toggle between hits and shots and restart state
|
||||||
* B long: Display "Error user unknwn"
|
* A + B: Display "Error user unknwn"
|
||||||
* A + B: Display "You lost the game" animation (losethegame.com - you're welcome!)
|
* B long: Display "You lost the game" animation (losethegame.com - you're welcome!)
|
||||||
**/
|
**/
|
||||||
class DefaultState : public AbstractStateHandler
|
class DefaultState : public AbstractStateHandler
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,8 +3,68 @@
|
||||||
#include "StateDefault.h"
|
#include "StateDefault.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "SegmentDisplayChars.h"
|
||||||
|
|
||||||
|
#define CharPipeLeft SegmentE | SegmentF
|
||||||
|
#define CharPipeRight SegmentB | SegmentC
|
||||||
|
|
||||||
|
|
||||||
|
struct Frame
|
||||||
|
{
|
||||||
|
uint32_t time;
|
||||||
|
char frame[6];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Frame const animation[] = {
|
||||||
|
// Snake towards the middle
|
||||||
|
{ 100, { SegmentF, 0, 0, 0, 0, SegmentB } },
|
||||||
|
{ 100, { SegmentF | SegmentE, 0, 0, 0, 0, SegmentB | SegmentC } },
|
||||||
|
{ 100, { SegmentE | SegmentD, 0, 0, 0, 0, SegmentC | SegmentD } },
|
||||||
|
{ 100, { SegmentD | SegmentC, 0, 0, 0, 0, SegmentD | SegmentE } },
|
||||||
|
{ 100, { SegmentC | SegmentB, 0, 0, 0, 0, SegmentE | SegmentF } },
|
||||||
|
|
||||||
|
{ 100, { SegmentB, SegmentF, 0, 0, SegmentB, SegmentF } },
|
||||||
|
{ 100, { 0, SegmentF | SegmentE, 0, 0, SegmentB | SegmentC, 0 } },
|
||||||
|
{ 100, { 0, SegmentE | SegmentD, 0, 0, SegmentC | SegmentD, 0 } },
|
||||||
|
{ 100, { 0, SegmentD | SegmentC, 0, 0, SegmentD | SegmentE, 0 } },
|
||||||
|
{ 100, { 0, SegmentC | SegmentB, 0, 0, SegmentE | SegmentF, 0 } },
|
||||||
|
|
||||||
|
{ 100, { 0, SegmentB, SegmentF, SegmentB, SegmentF, 0 } },
|
||||||
|
{ 100, { 0, 0, SegmentF | SegmentE, SegmentB | SegmentC, 0, 0 } },
|
||||||
|
{ 100, { 0, 0, SegmentE | SegmentD, SegmentC | SegmentD, 0, 0 } },
|
||||||
|
{ 100, { 0, 0, SegmentD | SegmentC, SegmentD | SegmentE, 0, 0 } },
|
||||||
|
{ 500, { 0, 0, SegmentC | SegmentB, SegmentE | SegmentF, 0, 0 } },
|
||||||
|
|
||||||
|
// Slide open to reveal 'you'
|
||||||
|
{ 100, { 0, 0, CharPipeLeft | CharO, CharU | CharPipeRight, 0, 0 } },
|
||||||
|
{ 100, { 0, CharPipeRight, CharO, CharU, CharPipeLeft, 0 } },
|
||||||
|
{ 100, { 0, CharPipeLeft | CharY, CharO, CharU, CharPipeRight, 0 } },
|
||||||
|
{ 100, { CharPipeRight, CharY, CharO, CharU, 0, CharPipeLeft } },
|
||||||
|
{ 100, { CharPipeLeft, CharY, CharO, CharU, 0, CharPipeRight } },
|
||||||
|
{ 500, { 0, CharY, CharO, CharU, 0, 0 } },
|
||||||
|
|
||||||
|
// The rest of the text
|
||||||
|
{ 750, { 0, CharL, CharO, CharS, CharT, 0 } },
|
||||||
|
{ 750, { 0, 0, CharT, CharH, CharE, 0 } },
|
||||||
|
{ 500, { SegmentDP, CharG, CharA | SegmentDP, CharM, CharE | SegmentDP, 0 } },
|
||||||
|
{ 500, { 0, CharG | SegmentDP, CharA, CharM | SegmentDP, CharE, SegmentDP } },
|
||||||
|
{ 500, { SegmentDP, CharG, CharA | SegmentDP, CharM, CharE | SegmentDP, 0 } },
|
||||||
|
{ 500, { 0, CharG | SegmentDP, CharA, CharM | SegmentDP, CharE, SegmentDP } },
|
||||||
|
{ 500, { SegmentDP, CharG, CharA | SegmentDP, CharM, CharE | SegmentDP, 0 } },
|
||||||
|
{ 500, { 0, CharG | SegmentDP, CharA, CharM | SegmentDP, CharE, SegmentDP } },
|
||||||
|
{ 500, { SegmentDP, CharG, CharA | SegmentDP, CharM, CharE | SegmentDP, 0 } },
|
||||||
|
{ 500, { 0, CharG | SegmentDP, CharA, CharM | SegmentDP, CharE, SegmentDP } },
|
||||||
|
|
||||||
|
{ 0, { 0, 0, 0, 0, 0, 0 } }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LoseTheGameState::setup()
|
void LoseTheGameState::setup()
|
||||||
{
|
{
|
||||||
|
animationTime = currentTime;
|
||||||
|
animationStep = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoseTheGameState::loop()
|
void LoseTheGameState::loop()
|
||||||
|
@ -14,6 +74,14 @@ void LoseTheGameState::loop()
|
||||||
setCurrentState(new DefaultState());
|
setCurrentState(new DefaultState());
|
||||||
}
|
}
|
||||||
|
|
||||||
char text[] = "Lost";
|
if (currentTime - animationTime > animation[animationStep].time)
|
||||||
display->writeTextLeft(text);
|
{
|
||||||
|
animationStep++;
|
||||||
|
animationTime = currentTime;
|
||||||
|
|
||||||
|
if (animation[animationStep].time == 0)
|
||||||
|
setCurrentState(new DefaultState());
|
||||||
|
}
|
||||||
|
|
||||||
|
display->writeRaw(animation[animationStep].frame);
|
||||||
}
|
}
|
|
@ -1,17 +1,25 @@
|
||||||
#ifndef StateLoseTheGame_h
|
#ifndef StateLoseTheGame_h
|
||||||
#define StateLoseTheGame_h
|
#define StateLoseTheGame_h
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
#include "StateHandler.h"
|
#include "StateHandler.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lose the game state
|
* Lose the game state
|
||||||
|
*
|
||||||
|
* Note that the animation in this state is hardcoded
|
||||||
|
* to 6 digits.
|
||||||
**/
|
**/
|
||||||
class LoseTheGameState : public AbstractStateHandler
|
class LoseTheGameState : public AbstractStateHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void setup();
|
void setup();
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned long animationTime;
|
||||||
|
byte animationStep;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
void UserUnknownState::setup()
|
void UserUnknownState::setup()
|
||||||
{
|
{
|
||||||
|
animationTime = currentTime;
|
||||||
|
animationStep = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserUnknownState::loop()
|
void UserUnknownState::loop()
|
||||||
|
@ -14,6 +16,50 @@ void UserUnknownState::loop()
|
||||||
setCurrentState(new DefaultState());
|
setCurrentState(new DefaultState());
|
||||||
}
|
}
|
||||||
|
|
||||||
char text[] = "Unknwn";
|
if (currentTime - animationTime > 500)
|
||||||
display->writeTextLeft(text);
|
{
|
||||||
|
animationStep++;
|
||||||
|
animationTime = currentTime;
|
||||||
|
|
||||||
|
if (animationStep == 12)
|
||||||
|
animationStep = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (animationStep)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
char text[] = "ERROR";
|
||||||
|
display->writeTextLeft(text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
case 3:
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
display->clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
case 7:
|
||||||
|
case 8:
|
||||||
|
{
|
||||||
|
char text[] = "user";
|
||||||
|
display->writeTextLeft(text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 9:
|
||||||
|
case 10:
|
||||||
|
case 11:
|
||||||
|
{
|
||||||
|
char text[] = "unknwn";
|
||||||
|
display->writeTextLeft(text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef StateUserUnknown_h
|
#ifndef StateUserUnknown_h
|
||||||
#define StateUserUnknown_h
|
#define StateUserUnknown_h
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
#include "StateHandler.h"
|
#include "StateHandler.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +15,10 @@ class UserUnknownState : public AbstractStateHandler
|
||||||
public:
|
public:
|
||||||
void setup();
|
void setup();
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned long animationTime;
|
||||||
|
byte animationStep;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue