forked from marmilicious/FastLED_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrigger_update_from_input.ino
72 lines (59 loc) · 2.24 KB
/
trigger_update_from_input.ino
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
//***************************************************************
// Example of using an input to trigger a pixel update.
//
// A simple button is used here, but the input could be modified
// to other types of inputs by changing the "checkInput" function
// that monitors the input.
//
// This example uses JChristensen's Button Library from:
// https://github.com/JChristensen/Button
//
//
// Marc Miller, Feb 2017
//***************************************************************
#include "FastLED.h"
#define DATA_PIN 11
#define CLK_PIN 13
#define LED_TYPE LPD8806
#define COLOR_ORDER GRB
#define NUM_LEDS 32
#define BRIGHTNESS 50
CRGB leds[NUM_LEDS];
// use JChristensen's Button library
#include "Button.h"
const int buttonPin = 4; // digital pin used for debounced push button
Button myButton(buttonPin, true, true, 40); // declare the button
uint8_t pos = NUM_LEDS-1; // set initial position
boolean input = false; // set input status
//---------------------------------------------------------------
void setup() {
Serial.begin(115200); // Allows serial monitor output (check baud rate)
delay(3000); // 3 second delay for recovery
//FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
Serial.println("Setup done. \n");
}
//---------------------------------------------------------------
void loop() {
checkInput(); // calls funtion to check the input
if (input == true) {
leds[pos] = CRGB::Black; // turn off previously lit pixel
pos++; // Advance to next pixel
if (pos == NUM_LEDS) { pos = 0; } // rollover if needed
leds[pos] = CHSV(random8(),255,255); // turn on new pixel with random color
//input = false; // set input status back to false
}
FastLED.show(); // update the display
}//end_main_loop
//---------------------------------------------------------------
void checkInput(){ // function to check input
myButton.read();
if(myButton.wasPressed() ) {
Serial.println("Button pressed!");
input = true; // set input status to true
} else {
input = false;
}
}//end_checkInput