Created
April 15, 2016 07:57
-
-
Save gatana/825d72c98711f8b22880b0a53b5f4fc7 to your computer and use it in GitHub Desktop.
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
#include "FastLED.h" | |
#define DATA_PIN 5 | |
#define CLOCK_PIN 6 | |
#define LED_TYPE DOTSTAR | |
#define COLOR_ORDER GRB | |
#define NUM_LEDS 15 | |
CRGB leds[NUM_LEDS]; | |
//#define BRIGHTNESS 96 | |
#define BRIGHTNESS 50 | |
#define FRAMES_PER_SECOND 120 | |
int hit; | |
const int buttonPin = 2; | |
int buttonPushCounter = 0; | |
int buttonState = 0; | |
int lastButtonState = 0; | |
uint8_t gHue = 0; // rotating "base color" used by many of the patterns | |
void setup() { | |
pinMode(buttonPin, INPUT); | |
delay(300); // 3 second delay for recovery | |
LEDS.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); | |
// set master brightness control | |
FastLED.setBrightness(BRIGHTNESS); | |
Serial.begin(9600); | |
} | |
void loop() { | |
buttonState = digitalRead(buttonPin); | |
Serial.print(buttonState); | |
if (buttonState != lastButtonState) { | |
if (buttonState == HIGH) { | |
buttonPushCounter++; | |
Serial.println("on"); | |
Serial.println(buttonPushCounter); | |
} else { | |
Serial.println("off"); | |
} | |
} | |
lastButtonState = buttonState; | |
FastLED.show(); | |
FastLED.delay(100 / FRAMES_PER_SECOND); | |
if (hit % 4 == 0) { | |
gHue++; | |
} | |
// use for | |
// EVERY_N_MILLISECONDS( 20 ) { | |
// gHue++; // slowly cycle the "base color" through the rainbow | |
// } | |
} | |
void beautiful() | |
{ | |
fadeToBlackBy(leds, NUM_LEDS, 20); | |
int pos = beatsin8(10, 0, NUM_LEDS); | |
leds[pos] += CHSV(gHue, 255, 192); | |
if (pos == 1 || pos == 15) { | |
hit++; | |
} | |
FastLED.show(); | |
FastLED.delay(100 / FRAMES_PER_SECOND); | |
if (hit % 4 == 0) { | |
gHue++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment