Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- CRGB leds[12];
- int MotionRead;
- int Motion;
- byte ledProgram;
- byte oldValue;
- unsigned long timer;
- unsigned long timer1;
- byte y;
- void pulsingWhite();
- void rainbow();
- void solidWhite();
- void off();
- void setup() {
- FastLED.addLeds<WS2812B, 1>(leds, 12);
- //MotionRead = analogRead(1);
- //Motion = map(MotionRead, 0, 1023, 0, 255);
- //oldValue = Motion;
- }
- void loop() {
- MotionRead = analogRead(1);
- Motion = map(MotionRead, 0, 1023, 0, 255);
- solidWhite();
- if (Motion - oldValue > 15 || oldValue - Motion > 15) {
- oldValue = Motion;
- if (millis() > timer1 + 1000) {
- ledProgram++;
- timer1 = millis();
- if (ledProgram > 4)ledProgram = 0;
- }
- }
- switch (ledProgram) {
- case 0:
- {
- solidWhite();
- break;
- }
- case 1:
- {
- pulsingWhite();
- break;
- }
- case 2:
- {
- candle();
- break;
- }
- case 3:
- {
- rainbow();
- break;
- }
- case 4:
- {
- off();
- break;
- }
- }
- FastLED.show();
- }
- void solidWhite() {
- for (int x = 0; x < 12; x++) {
- leds[x] = CHSV(0, 0 , 255);
- }
- }
- void pulsingWhite() {
- if (millis() > timer + 100) {
- y++;
- //if (y == 255)y = 0;
- timer = millis();
- }
- for (int x = 0; x < 12; x++) {
- leds[x] = CHSV(0, 0, y);
- }
- }
- void candle() {
- if (millis() > timer + 400) {
- for (int x = 0; x < 12; x++) {
- y = random8();
- leds[x] = CHSV(0, 0, 255 - y);
- }
- timer = millis();
- }
- }
- void rainbow() {
- if (millis() > timer + 100) {
- y++;
- //if (y == 255)y = 0;
- timer = millis();
- }
- for (int x = 0; x < 12; x++) {
- leds[x] = CHSV(y, 255, 255);
- }
- }
- void off() {
- for (int x = 0; x < 12; x++) {
- leds[x] = CHSV(0, 0, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment