forked from Aircoookie/WLED
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Aircoookie#60 from Aircoookie/master
Add on
- Loading branch information
Showing
5 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Battery powered controller with keypad | ||
|
||
I'm using this controller for a festival totem. Runs on 3 18650 Cells, can deliver >5A current. | ||
|
||
Via keypad one can select 8 presets, change effect, effect speed, effect intensity and palette. Brightness can be | ||
adjusted with a potentiometer. | ||
|
||
## Pictures | ||
|
||
![bat-key-ctrl-1](assets/bat-key-ctrl-1.jpg) | ||
![bat-key-ctrl-2](assets/bat-key-ctrl-2.jpg) | ||
![bat-key-ctrl-3](assets/bat-key-ctrl-3.jpg) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* WLED usermod for keypad and brightness-pot. | ||
* 3'2020 https://github.com/hobbyquaker | ||
*/ | ||
|
||
#include <Keypad.h> | ||
const byte keypad_rows = 4; | ||
const byte keypad_cols = 4; | ||
char keypad_keys[keypad_rows][keypad_cols] = { | ||
{'1', '2', '3', 'A'}, | ||
{'4', '5', '6', 'B'}, | ||
{'7', '8', '9', 'C'}, | ||
{'*', '0', '#', 'D'} | ||
}; | ||
|
||
byte keypad_colPins[keypad_rows] = {D3, D2, D1, D0}; | ||
byte keypad_rowPins[keypad_cols] = {D7, D6, D5, D4}; | ||
|
||
Keypad myKeypad = Keypad(makeKeymap(keypad_keys), keypad_rowPins, keypad_colPins, keypad_rows, keypad_cols); | ||
|
||
void userSetup() | ||
{ | ||
|
||
} | ||
|
||
void userConnected() | ||
{ | ||
|
||
} | ||
|
||
long lastTime = 0; | ||
int delayMs = 20; //we want to do something every 2 seconds | ||
|
||
void userLoop() | ||
{ | ||
if (millis()-lastTime > delayMs) | ||
{ | ||
|
||
long analog = analogRead(0); | ||
int new_bri = 1; | ||
if (analog > 900) { | ||
new_bri = 255; | ||
} else if (analog > 30) { | ||
new_bri = dim8_video(map(analog, 31, 900, 16, 255)); | ||
} | ||
if (bri != new_bri) { | ||
bri = new_bri; | ||
colorUpdated(1); | ||
|
||
} | ||
|
||
char myKey = myKeypad.getKey(); | ||
if (myKey != NULL) { | ||
switch (myKey) { | ||
case '1': | ||
applyPreset(1); | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case '2': | ||
applyPreset(2); | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case '3': | ||
applyPreset(3); | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case '4': | ||
applyPreset(4); | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case '5': | ||
applyPreset(5); | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case '6': | ||
applyPreset(6); | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case 'A': | ||
applyPreset(7); | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case 'B': | ||
applyPreset(8); | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
|
||
case '7': | ||
effectCurrent += 1; | ||
if (effectCurrent >= MODE_COUNT) effectCurrent = 0; | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case '*': | ||
effectCurrent -= 1; | ||
if (effectCurrent < 0) effectCurrent = (MODE_COUNT-1); | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
|
||
case '8': | ||
if (effectSpeed < 240) { | ||
effectSpeed += 12; | ||
} else if (effectSpeed < 255) { | ||
effectSpeed += 1; | ||
} | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case '0': | ||
if (effectSpeed > 15) { | ||
effectSpeed -= 12; | ||
} else if (effectSpeed > 0) { | ||
effectSpeed -= 1; | ||
} | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
|
||
case '9': | ||
if (effectIntensity < 240) { | ||
effectIntensity += 12; | ||
} else if (effectIntensity < 255) { | ||
effectIntensity += 1; | ||
} | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case '#': | ||
if (effectIntensity > 15) { | ||
effectIntensity -= 12; | ||
} else if (effectIntensity > 0) { | ||
effectIntensity -= 1; | ||
} | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
|
||
case 'C': | ||
effectPalette += 1; | ||
if (effectPalette >= 50) effectPalette = 0; | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
case 'D': | ||
effectPalette -= 1; | ||
if (effectPalette <= 0) effectPalette = 50; | ||
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED); | ||
break; | ||
|
||
} | ||
|
||
} | ||
|
||
lastTime = millis(); | ||
} | ||
|
||
} |