Skip to content

Commit e06c6e9

Browse files
authored
Merge pull request #86 from Legion2/ls100-button
Added ON/OFF button to LS100
2 parents a60e04b + 175c0df commit e06c6e9

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

examples/LS100/LS100.ino

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#define DATA_PIN_CHANNEL_1 2
2121
#define DATA_PIN_CHANNEL_2 3
2222

23+
#define BUTTON_PIN 4
24+
2325
CRGB ledsChannel1[135];
2426
CRGB ledsChannel2[135];
2527

@@ -33,12 +35,37 @@ void setup() {
3335
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_2>(ledsChannel2, 135);
3436
ledController.addLEDs(0, ledsChannel1, 135);
3537
ledController.addLEDs(1, ledsChannel2, 135);
38+
pinMode(BUTTON_PIN, INPUT_PULLUP);
3639
}
3740

3841
void loop() {
42+
static bool lightingEnabled = true;
3943
cHID.update();
4044

41-
if (ledController.updateLEDs()) {
42-
FastLED.show();
45+
if (buttonClicked()) {
46+
lightingEnabled = !lightingEnabled;
47+
fill_solid(ledsChannel1, 135, CRGB::Black);
48+
fill_solid(ledsChannel2, 135, CRGB::Black);
49+
FastLED.show();
50+
}
51+
52+
if (lightingEnabled && ledController.updateLEDs()) {
53+
FastLED.show();
4354
}
4455
}
56+
57+
/**
58+
* Handle button of the LS100. The button is optional.
59+
*
60+
* @return true if the button was pressed and then released.
61+
*/
62+
bool buttonClicked() {
63+
static bool previousState = 1;
64+
bool state = digitalRead(BUTTON_PIN);
65+
if (previousState == 0 && state == 1) {
66+
previousState = state;
67+
return true;
68+
}
69+
previousState = state;
70+
return false;
71+
}

0 commit comments

Comments
 (0)