Editing
GlowHood
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Code == === Twinkle`Z w/Button Button Hack === <pre> #include "FastLED.h" // How many leds in your strip? #define NUM_LEDS 72 #define NUM_TWINK 8 // Delay between cycles #define LOOP_DELAY 50 // Strip Data In (DI) #define DATA_PIN 11 #define HOLD_THRESHOLD 200 #define STANDBY_TIME 5000 // Define the array of leds CRGB leds[NUM_LEDS]; int twinklePos[NUM_TWINK]; byte twinkleHue[NUM_TWINK]; byte twinkleVal[NUM_TWINK]; unsigned long lastTime = 0; unsigned long holdTime = 0; boolean standbyMode = false; void setup() { pinMode(13, OUTPUT); Serial.begin(9600); FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); FastLED.setBrightness(96); for (int i = 0; i < NUM_TWINK; i++) { twinklePos[i] = 0; twinkleHue[i] = 0; twinkleVal[i] = 0; } delay(200); } void loop() { // Twinkle`Z for (int j = 0; j < NUM_TWINK; j++) { if (twinkleVal[j] == 0) { int led = random(0, NUM_LEDS); twinklePos[j] = led; twinkleHue[j] = random(0, 255); twinkleVal[j] = random(32, 255); } else { twinkleHue[j] += random(-32, 32); twinkleVal[j] += random(-32, 8); if (twinkleVal[j] <= 32) { // Done twinkleVal[j] = 0; } } } int button = analogRead(A0); unsigned long now = millis(); boolean onOff = button < 96 || button > 927; if (onOff) lastTime = now; if (now - holdTime > STANDBY_TIME) { // Change mode if (!standbyMode) { for (int l = 0; l < NUM_LEDS; l++) { leds[l] = CHSV(0, 0, 0); FastLED.show(); } } standbyMode = !standbyMode; holdTime = now; } if (onOff != digitalRead(13) == HIGH) { if (onOff) { holdTime = now; digitalWrite(13, HIGH); } else if (now - lastTime > HOLD_THRESHOLD) { digitalWrite(13, LOW); } } for (int i = 0; i < NUM_TWINK; i++) { leds[twinklePos[i]] = CHSV(twinkleHue[i], onOff ? 0 : 255, twinkleVal[i]); } if (!standbyMode) FastLED.show(); Serial.println(String(button)); if (digitalRead(13) == HIGH) { delay(LOOP_DELAY / 5); } else { holdTime = now; delay(LOOP_DELAY); } // Serial.println(String(standbyMode) + ", " + String(onOff) + ", " + String(now - holdTime)); } </pre> === Multi-mode demo with Serial === <pre> /* * Serial control interface for LED Strip * * Updated: 20140921 * * Command Summary: * MODE0 == Auto (Rainbeau) * MODE1 == Off * MODE2 == Remote (PC Control) * HH..H == Sequence of Hue values to apply to LEDs * Note: Set "MODE2" before sending hues * S == Set saturation * MODE3 == Center Peak Rainbeau * MODE4 == Center Peak Pastel */ #include "FastLED.h" // How many leds in your strip? #define NUM_LEDS 72 // Spacing between pixel/color #define HSV_PAD 4 // Delay between cycles #define LOOP_DELAY 50 // Strip Data In (DI) #define DATA_PIN 11 // Define the array of leds CRGB leds[NUM_LEDS]; float counter = 0; byte count = 0; byte mode = 4; byte hues[NUM_LEDS]; byte sat = 255; // Saturation 0-255 String inputString = ""; void setup() { pinMode(13, OUTPUT); for (int i = 0; i < NUM_LEDS; i++) { hues[i] = 0; } FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); // Max brightness 0-255 (64 ~< 100ma for 12 LEDs) FastLED.setBrightness(64); Serial.begin(9600); Serial.setTimeout(50); delay(200); } void loop() { int i; int v; float p; if (mode == 0) { // Rainbeau for (i = 0; i < NUM_LEDS; i++) { leds[i] = CHSV(count + (i * HSV_PAD), sat, 255); } FastLED.show(); count++; delay(LOOP_DELAY); } else if (mode == 1) { // Off for (i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB(0, 0, 0); } FastLED.show(); delay(LOOP_DELAY); } else if (mode == 2) { // Remote +hex } else if (mode == 3) { // Rainbeau for (i = 0; i < NUM_LEDS; i++) { // variable position dimming // Set 'p' to 0.0 - 1.0 so the ends are 0.0 and the center is 1.0 p = (((NUM_LEDS / 2) - abs(i - (NUM_LEDS / 2.0)))) / (NUM_LEDS / 2.0); v = min(255, round(p * 255.0) + 64); // sin function added for oscillating color change counter += 0.000001337; count = sin(counter * 3.14 * 180) * 255 + (i * HSV_PAD); leds[i] = CHSV(count, sat, v);// - (v/1.5), v); } FastLED.show(); count++; delay(LOOP_DELAY); } else if (mode == 4) { // Rainbeau for (i = 0; i < NUM_LEDS; i++) { // variable position dimming // Set 'p' to 0.0 - 1.0 so the ends are 0.0 and the center is 1.0 p = (((NUM_LEDS / 2) - abs(i - (NUM_LEDS / 2.0)))) / (NUM_LEDS / 2.0); v = min(255, round(p * 255.0) + 64); // sin function added for oscillating color change counter += 0.000001337; count = sin(counter * 3.14 * 180) * 255 + (i * HSV_PAD); leds[i] = CHSV(count, sat - (v/1.5), v); } FastLED.show(); count++; delay(LOOP_DELAY); } } void updateHues() { for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CHSV(hues[i], 255, 255); } FastLED.show(); // Toggle onboard LED digitalWrite(13, !digitalRead(13)); } void serialEvent() { byte byteCount = 0; byte data; inputString = ""; while(Serial.available()) { data = Serial.read(); inputString += (char)data; if (byteCount < NUM_LEDS) { hues[byteCount++] = byte(data + 90); } // Catch pending bits if (!Serial.available()) delay(20); } if (inputString == "MODE0") { mode = 0; } else if (inputString == "MODE1") { mode = 1; } else if (inputString == "MODE2") { mode = 2; } else if (inputString == "MODE3") { mode = 3; } else if (inputString == "MODE4") { mode = 4; } else if (inputString.length() == NUM_LEDS) { updateHues(); } else if (inputString.length() == 1) { sat = data; } } </pre>
Summary:
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Noisebridge:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Request account
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Dig in!
Noisebridge
- Status: MOVED
- Donate
- ABOUT
- Accessibility
- Vision
- Blog
Manual
MANUAL
Visitors
Participation
Community Standards
Channels
Operations
Events
EVENTS
Guilds
GUILDS
- Meta
- Electronics
- Fabrication
- Games
- Music
- Library
- Neuro
- Philosophy
- Funding
- Art
- Crypto
- Documentation/Wiki
Wiki
Recent Changes
Random Page
Help
Categories
(Edit)
Tools
What links here
Related changes
Special pages
Page information