Skip to content

Commit 66d5689

Browse files
Feature Development for UI and User Experience Improvment
* Basic execution improvement and project settings * Fixing compilation warning in SceneManager * Removing MainApp class to reduce memory footprint * PNG files renaming for in readme.md name match * Blinking duration extension capabilities Fixing ATtiny naming and addition of details on the blink duration extension. * SceneManagerClass init function renamed to begin. Fix SceneManager.begin() not called at firmware initialization * SceneManagerClass init function renamed to begin. Fix SceneManager.begin() not called at firmware initialization Forcing Light to Off at initialization * Fixing algo forcing system to start and stay in undefined state for the SceneManager internal state machine. * Remove unused MainApp files * Documentation update for revision 1.2
1 parent 92e13df commit 66d5689

9 files changed

+195
-303
lines changed

BlinkyBike/BlinkyBike/BlinkyBike.ino

+127-4
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,142 @@
2323
* | _ <| | | '_ \| |/ / | | | | _ <| | |/ / _ \
2424
* | |_) | | | | | | <| |_| | | |_) | | < __/
2525
* |____/|_|_|_| |_|_|\_\\__, | |____/|_|_|\_\___|
26-
* __/ | Version 1.1
26+
* __/ | Version 1.2
2727
* |___/
2828
*
2929
*****************************************************************************/
3030

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+
}
3296

3397
// the setup function runs once when you press reset or power the board
3498
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();
36116
}
37117

38118
// the loop function runs over and over again until power down or reset
39119
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();
41164
}

BlinkyBike/BlinkyBike/BlinkyBike.vcxproj

+5-4
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@
8181
<ClInclude Include="Button.h">
8282
<FileType>CppCode</FileType>
8383
</ClInclude>
84-
<ClInclude Include="MainApp.h">
85-
<FileType>CppCode</FileType>
86-
</ClInclude>
8784
<ClInclude Include="SceneManager.h">
8885
<FileType>CppCode</FileType>
8986
</ClInclude>
@@ -100,11 +97,15 @@
10097
<ClCompile Include="AnimationPlayer.cpp" />
10198
<ClCompile Include="Animations.cpp" />
10299
<ClCompile Include="Button.cpp" />
103-
<ClCompile Include="MainApp.cpp" />
104100
<ClCompile Include="SceneManager.cpp" />
105101
<ClCompile Include="Timer.cpp" />
106102
</ItemGroup>
107103
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
108104
<ImportGroup Label="ExtensionTargets">
109105
</ImportGroup>
106+
<ProjectExtensions>
107+
<VisualStudio>
108+
<UserProperties vm.upload.useprogrammer="1" />
109+
</VisualStudio>
110+
</ProjectExtensions>
110111
</Project>

BlinkyBike/BlinkyBike/MainApp.cpp

-143
This file was deleted.

0 commit comments

Comments
 (0)