-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSplitFlapLetter.h
99 lines (82 loc) · 2.49 KB
/
SplitFlapLetter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) 2020 Stefano Guglielmetti
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#ifndef SPLIT_FLAP_LETTER_H
#define SPLIT_FLAP_LETTER_H
#include <Arduino.h>
#define STATE_IDLE 0
#define STATE_RESET 1
#define STATE_PRINTING 2
class SplitFlapLetter {
public:
/*!
@brief SplitFlapLetter constructor when no parameters are provided
used to initialize the internal array of letters in
SplitFlapDisplay
*/
SplitFlapLetter();
/*!
@brief SplitFlapLetter constructor
@param relayPin arduino pin of the letter's relay
@param hallPin arduino pin of the letter's relay
*/
SplitFlapLetter(int relayPin, int hallPin);
/*!
@brief SplitFlapLetter initialization. Assigns params to the internal
member variables
*/
void init();
/*!
@brief Resets the letter to blank
*/
void reset();
/*!
@brief Refreshes the letter state. Usyal be called at each Arduino loop,
usually invoked by SplitFlapDisplay
*/
void refresh();
/*!
@brief Letter's ready state, true if the letter is not flapping (state is
STATE_IDLE).
@return Letter ready state (boolean).
*/
bool isReady();
/*!
@brief Show the provided character, only if present in the ALPHABET array.
@param letter the charater to display.
*/
void print(char letter);
/*!
@brief Flaps the letter. Definitely should be private. It's public only for
demo purposes, to manually flap the display and play nice 1 note
songs.
*/
void flap();
private:
static const char ALPHABET[40];
byte state; ///< Internal state, could be STATE_IDLE, STATE_RESET,
///< STATE_PRINTING
byte relayPin; ///< Arduino pin of the relay
byte hallPin; ///< Arduino pin of the hall sensor
byte currentPosition = 0; ///< index of active character
char targetLetter = ' '; ///< character to display
bool relayState = 0; ///< internal state of the relay. Changes at every flap.
bool shouldFlap = 0; ///< wheter it should flap or not in the next iteration
/*!
@brief increments current position and resets it to 0 when reaches the
total letters number
*/
void incrementPosition();
/*!
@brief active character
@return active character (char)
*/
char currentLetter();
/*!
@brief verifies if the provided character is present it the ALPHABET array
@return true or false
*/
bool isValidLetter(char letter);
};
#endif