|
23 | 23 | * | _ <| | | '_ \| |/ / | | | | _ <| | |/ / _ \
|
24 | 24 | * | |_) | | | | | | <| |_| | | |_) | | < __/
|
25 | 25 | * |____/|_|_|_| |_|_|\_\\__, | |____/|_|_|\_\___|
|
26 |
| - * __/ | Version 1.1 |
| 26 | + * __/ | Version 1.2 |
27 | 27 | * |___/
|
28 | 28 | *
|
29 | 29 | *****************************************************************************/
|
30 | 30 |
|
31 |
| -#include "MainApp.h" |
| 31 | +#if defined(ARDUINO) && ARDUINO >= 100 |
| 32 | + #include "arduino.h" |
| 33 | +#else |
| 34 | + #include "WProgram.h" |
| 35 | +#endif |
| 36 | + |
| 37 | +#include "Adafruit_NeoPixel.h" |
| 38 | +#include "Timer.h" |
| 39 | +#include "Button.h" |
| 40 | +#include "Stripes.h" |
| 41 | +#include "SceneManager.h" |
| 42 | + |
| 43 | +// LED Stripes configuration |
| 44 | +// See Stripes.h |
| 45 | + |
| 46 | +// Buttons configuration |
| 47 | +#define BUTTON_LEFT_PIN 3 |
| 48 | +#define BUTTON_RIGHT_PIN 2 |
| 49 | + |
| 50 | +#define BUTTON_DEBOUNCE_TIMEOUT 10 |
| 51 | +#define BUTTON_STATE_TIMEOUT 200 |
| 52 | +#define BUTTON_HOLD_TIMEOUT (1 * 1000) |
| 53 | + |
| 54 | +// Scenes timer index |
| 55 | +#define SCENE_TIMER_FRONT 0 |
| 56 | +#define SCENE_TIMER_REAR_LEFT 1 |
| 57 | +#define SCENE_TIMER_REAR_RIGHT 2 |
| 58 | + |
| 59 | + |
| 60 | +// LED Stripes |
| 61 | +Adafruit_NeoPixel frontLight = Adafruit_NeoPixel(LED_STRIPE_FRONT_NUMLED, LED_STRIPE_FRONT_PIN, NEO_GRB + NEO_KHZ800); |
| 62 | +Adafruit_NeoPixel rearLeftLight = Adafruit_NeoPixel(LED_STRIPE_REARLEFT_NUMLED, LED_STRIPE_REARLEFT_PIN, NEO_GRB + NEO_KHZ800); |
| 63 | +Adafruit_NeoPixel rearRightLight = Adafruit_NeoPixel(LED_STRIPE_REARRIGHT_NUMLED, LED_STRIPE_REARRIGHT_PIN, NEO_GRB + NEO_KHZ800); |
| 64 | + |
| 65 | +// Buttons |
| 66 | +Button leftButton = Button(BUTTON_LEFT_PIN, BUTTON_DEBOUNCE_TIMEOUT, BUTTON_HOLD_TIMEOUT, BUTTON_STATE_TIMEOUT, BUTTON_PULLUP); |
| 67 | +Button rightButton = Button(BUTTON_RIGHT_PIN, BUTTON_DEBOUNCE_TIMEOUT, BUTTON_HOLD_TIMEOUT, BUTTON_STATE_TIMEOUT, BUTTON_PULLUP); |
| 68 | + |
| 69 | +// Timers |
| 70 | +Timer appTimer = Timer(); |
| 71 | + |
| 72 | + |
| 73 | +/// <summary> |
| 74 | +/// Front Timer callback function |
| 75 | +/// </summary> |
| 76 | +void loadSceneFront_callback() |
| 77 | +{ |
| 78 | + SceneManager.nextSceneStepFront(); |
| 79 | +} |
| 80 | + |
| 81 | +/// <summary> |
| 82 | +/// Rear Left Timer callback function |
| 83 | +/// </summary> |
| 84 | +void loadSceneRearLeft_callback() |
| 85 | +{ |
| 86 | + SceneManager.nextSceneStepRearLeft(); |
| 87 | +} |
| 88 | + |
| 89 | +/// <summary> |
| 90 | +/// Rear Right Timer callback function |
| 91 | +/// </summary> |
| 92 | +void loadSceneRearRight_callback() |
| 93 | +{ |
| 94 | + SceneManager.nextSceneStepRearRight(); |
| 95 | +} |
32 | 96 |
|
33 | 97 | // the setup function runs once when you press reset or power the board
|
34 | 98 | void setup() {
|
35 |
| - MainApp.init(); |
| 99 | + // Initialize the LED Stripes |
| 100 | + frontLight.begin(); |
| 101 | + rearLeftLight.begin(); |
| 102 | + rearRightLight.begin(); |
| 103 | + |
| 104 | + // Initialize the timer |
| 105 | + appTimer.configureTimer(SCENE_TIMER_FRONT, 2 * 1000, loadSceneFront_callback); |
| 106 | + appTimer.configureTimer(SCENE_TIMER_REAR_LEFT, 2 * 1000, loadSceneRearLeft_callback); |
| 107 | + appTimer.configureTimer(SCENE_TIMER_REAR_RIGHT, 2 * 1000, loadSceneRearRight_callback); |
| 108 | + |
| 109 | + // Clear the LED Stripes |
| 110 | + frontLight.show(); |
| 111 | + rearLeftLight.show(); |
| 112 | + rearRightLight.show(); |
| 113 | + |
| 114 | + // Initialize the SceneManager |
| 115 | + SceneManager.begin(); |
36 | 116 | }
|
37 | 117 |
|
38 | 118 | // the loop function runs over and over again until power down or reset
|
39 | 119 | void loop() {
|
40 |
| - MainApp.loop(); |
| 120 | + // Update the button state |
| 121 | + ButtonState leftButtonState = leftButton.getButtonState(); |
| 122 | + ButtonState rightButtonState = rightButton.getButtonState(); |
| 123 | + |
| 124 | + // Update the scene based on button state |
| 125 | + SceneManager.updateScene(leftButtonState, rightButtonState); |
| 126 | + |
| 127 | + // Reset short press state |
| 128 | + leftButton.clearButtonState(); |
| 129 | + rightButton.clearButtonState(); |
| 130 | + |
| 131 | + // Handle scene updates |
| 132 | + // Updates occurs on Timer elapsed and call to updateScene |
| 133 | + // Front |
| 134 | + if (SceneManager.isSceneUpdatedFront() == true) |
| 135 | + { |
| 136 | + // update the timer for current step duration |
| 137 | + appTimer.updateTimer(SCENE_TIMER_FRONT, SceneManager.getSceneStepDurationFront()); |
| 138 | + } |
| 139 | + |
| 140 | + // Rear Left |
| 141 | + if (SceneManager.isSceneUpdatedRearLeft() == true) |
| 142 | + { |
| 143 | + // update the timer for current step duration |
| 144 | + appTimer.updateTimer(SCENE_TIMER_REAR_LEFT, SceneManager.getSceneStepDurationRearLeft()); |
| 145 | + } |
| 146 | + |
| 147 | + // Rear Right |
| 148 | + if (SceneManager.isSceneUpdatedRearRight() == true) |
| 149 | + { |
| 150 | + // update the timer for current step duration |
| 151 | + appTimer.updateTimer(SCENE_TIMER_REAR_RIGHT, SceneManager.getSceneStepDurationRearRight()); |
| 152 | + } |
| 153 | + |
| 154 | + // Update the LED Stripes |
| 155 | + SceneManager.updateStripes(&frontLight, &rearLeftLight, &rearRightLight); |
| 156 | + |
| 157 | + // Display the LED Stripes |
| 158 | + frontLight.show(); |
| 159 | + rearLeftLight.show(); |
| 160 | + rearRightLight.show(); |
| 161 | + |
| 162 | + // Update timer info |
| 163 | + appTimer.run(); |
41 | 164 | }
|
0 commit comments