Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include "FastLED.h" #include <EEPROM.h> #define NUM_LEDS 150 CRGB leds[NUM_LEDS]; #define PIN 5 #define BRIGHTNESS 100 #define BUTTON 2 byte selectedEffect=0; void setup() { FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); pinMode(2,INPUT_PULLUP); // internal pull-up resistor attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // pressed digitalWrite(2, HIGH); // turn on pullup resistors delay(100); // little 100ms delay before attaching the interrupt for the button } // *** REPLACE FROM HERE *** void loop() { EEPROM.get(0,selectedEffect); if(selectedEffect>9) { selectedEffect=0; EEPROM.put(0,0); } switch(selectedEffect) { case 1 : { // NewKITT - Color (red, green, blue), eye size, speed delay, end pause NewKITT(0x00, 0xff, 0x11, 8, 10, 50); break; } case 2 : { // Twinkle - Color (red, green, blue), count, speed delay, only one twinkle (true/false) RunningLights(0xff,0xd7,0x00, 50); break; } case 3 : { // Sparkle - Color (red, green, blue), speed delay Sparkle(0x4d, 0x4d, 0xff, 0); break; } case 4 : { // SnowSparkle - Color (red, green, blue), sparkle delay, speed delay SnowSparkle(0x38, 0x00, 0x33, 20, random(100,1000)); break; } case 5 : { // rainbowCycle - speed delay rainbowCycle(20); break; } case 6 : { // theaterChaseRainbow - Speed delay theaterChaseRainbow(50); break; } case 7 : { // Fire - Cooling rate, Sparking rate, speed delay Fire(55,120,15); break; } // simple bouncingBalls not included, since BouncingColoredBalls can perform this as well as shown below // BouncingColoredBalls - Number of balls, color (red, green, blue) array, continuous // CAUTION: If set to continuous then this effect will never stop!!! case 8 : { // meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay meteorRain(0x38,0x00,0xff,10, 64, true, 30); break; } } } void changeEffect() { if (digitalRead (BUTTON) == HIGH) { selectedEffect++; EEPROM.put(0, selectedEffect); asm volatile (" jmp 0"); } } // ************************* // ** LEDEffect Functions ** // ************************* void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){ RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay); LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay); OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay); CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay); LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay); RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay); OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay); CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay); } // used by NewKITT void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) { setAll(0,0,0); setPixel(i, red/10, green/10, blue/10); for(int j = 1; j <= EyeSize; j++) { setPixel(i+j, red, green, blue); } setPixel(i+EyeSize+1, red/10, green/10, blue/10); setPixel(NUM_LEDS-i, red/10, green/10, blue/10); for(int j = 1; j <= EyeSize; j++) { setPixel(NUM_LEDS-i-j, red, green, blue); } setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10); showStrip(); delay(SpeedDelay); } delay(ReturnDelay); } // used by NewKITT void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) { setAll(0,0,0); setPixel(i, red/10, green/10, blue/10); for(int j = 1; j <= EyeSize; j++) { setPixel(i+j, red, green, blue); } setPixel(i+EyeSize+1, red/10, green/10, blue/10); setPixel(NUM_LEDS-i, red/10, green/10, blue/10); for(int j = 1; j <= EyeSize; j++) { setPixel(NUM_LEDS-i-j, red, green, blue); } setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10); showStrip(); delay(SpeedDelay); } delay(ReturnDelay); } // used by NewKITT void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) { setAll(0,0,0); setPixel(i, red/10, green/10, blue/10); for(int j = 1; j <= EyeSize; j++) { setPixel(i+j, red, green, blue); } setPixel(i+EyeSize+1, red/10, green/10, blue/10); showStrip(); delay(SpeedDelay); } delay(ReturnDelay); } // used by NewKITT void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) { setAll(0,0,0); setPixel(i, red/10, green/10, blue/10); for(int j = 1; j <= EyeSize; j++) { setPixel(i+j, red, green, blue); } setPixel(i+EyeSize+1, red/10, green/10, blue/10); showStrip(); delay(SpeedDelay); } delay(ReturnDelay); } void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) { setAll(0,0,0); for (int i=0; i<Count; i++) { setPixel(random(NUM_LEDS),red,green,blue); showStrip(); delay(SpeedDelay); if(OnlyOne) { setAll(0,0,0); } } delay(SpeedDelay); } void Sparkle(byte red, byte green, byte blue, int SpeedDelay) { int Pixel = random(NUM_LEDS); setPixel(Pixel,red,green,blue); showStrip(); delay(SpeedDelay); setPixel(Pixel,0,0,0); } void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) { setAll(red,green,blue); int Pixel = random(NUM_LEDS); setPixel(Pixel,0xff,0xff,0xff); showStrip(); delay(SparkleDelay); setPixel(Pixel,red,green,blue); showStrip(); delay(SpeedDelay); } void RunningLights(byte red, byte green, byte blue, int WaveDelay) { int Position=0; for(int i=0; i<NUM_LEDS*2; i++) { Position++; // = 0; //Position + Rate; for(int i=0; i<NUM_LEDS; i++) { // sine wave, 3 offset waves make a rainbow! //float level = sin(i+Position) * 127 + 128; //setPixel(i,level,0,0); //float level = sin(i+Position) * 127 + 128; setPixel(i,((sin(i+Position) * 127 + 128)/255)*red, ((sin(i+Position) * 127 + 128)/255)*green, ((sin(i+Position) * 127 + 128)/255)*blue); } showStrip(); delay(WaveDelay); } } void rainbowCycle(int SpeedDelay) { byte *c; uint16_t i, j; for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel for(i=0; i< NUM_LEDS; i++) { c=Wheel(((i * 256 / NUM_LEDS) + j) & 255); setPixel(i, *c, *(c+1), *(c+2)); } showStrip(); delay(SpeedDelay); } } // used by rainbowCycle and theaterChaseRainbow byte * Wheel(byte WheelPos) { static byte c[3]; if(WheelPos < 85) { c[0]=WheelPos * 3; c[1]=255 - WheelPos * 3; c[2]=0; } else if(WheelPos < 170) { WheelPos -= 85; c[0]=255 - WheelPos * 3; c[1]=0; c[2]=WheelPos * 3; } else { WheelPos -= 170; c[0]=0; c[1]=WheelPos * 3; c[2]=255 - WheelPos * 3; } return c; } void theaterChaseRainbow(int SpeedDelay) { byte *c; for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel for (int q=0; q < 3; q++) { for (int i=0; i < NUM_LEDS; i=i+3) { c = Wheel( (i+j) % 255); setPixel(i+q, *c, *(c+1), *(c+2)); //turn every third pixel on } showStrip(); delay(SpeedDelay); for (int i=0; i < NUM_LEDS; i=i+3) { setPixel(i+q, 0,0,0); //turn every third pixel off } } } } void Fire(int Cooling, int Sparking, int SpeedDelay) { static byte heat[NUM_LEDS]; int cooldown; // Step 1. Cool down every cell a little for( int i = 0; i < NUM_LEDS; i++) { cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2); if(cooldown>heat[i]) { heat[i]=0; } else { heat[i]=heat[i]-cooldown; } } // Step 2. Heat from each cell drifts 'up' and diffuses a little for( int k= NUM_LEDS - 1; k >= 2; k--) { heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3; } // Step 3. Randomly ignite new 'sparks' near the bottom if( random(255) < Sparking ) { int y = random(7); heat[y] = heat[y] + random(160,255); //heat[y] = random(160,255); } // Step 4. Convert heat to LED colors for( int j = 0; j < NUM_LEDS; j++) { setPixelHeatColor(j, heat[j] ); } showStrip(); delay(SpeedDelay); } void setPixelHeatColor (int Pixel, byte temperature) { // Scale 'heat' down from 0-255 to 0-191 byte t192 = round((temperature/255.0)*191); // calculate ramp up from byte heatramp = t192 & 0x3F; // 0..63 heatramp <<= 2; // scale up to 0..252 // figure out which third of the spectrum we're in: if( t192 > 0x80) { // hottest setPixel(Pixel, 255, 255, heatramp); } else if( t192 > 0x40 ) { // middle setPixel(Pixel, 255, heatramp, 0); } else { // coolest setPixel(Pixel, heatramp, 0, 0); } } void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) { setAll(0,0,0); for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) { // fade brightness all LEDs one step for(int j=0; j<NUM_LEDS; j++) { if( (!meteorRandomDecay) || (random(10)>5) ) { fadeToBlack(j, meteorTrailDecay ); } } // draw meteor for(int j = 0; j < meteorSize; j++) { if( ( i-j <NUM_LEDS) && (i-j>=0) ) { setPixel(i-j, red, green, blue); } } showStrip(); delay(SpeedDelay); } } // used by meteorrain void fadeToBlack(int ledNo, byte fadeValue) { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel uint32_t oldColor; uint8_t r, g, b; int value; oldColor = strip.getPixelColor(ledNo); r = (oldColor & 0x00ff0000UL) >> 16; g = (oldColor & 0x0000ff00UL) >> 8; b = (oldColor & 0x000000ffUL); r=(r<=10)? 0 : (int) r-(r*fadeValue/256); g=(g<=10)? 0 : (int) g-(g*fadeValue/256); b=(b<=10)? 0 : (int) b-(b*fadeValue/256); strip.setPixelColor(ledNo, r,g,b); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED leds[ledNo].fadeToBlackBy( fadeValue ); #endif } // *** REPLACE TO HERE *** // *************************************** // ** FastLed/NeoPixel Common Functions ** // *************************************** // Apply LED color changes void showStrip() { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.show(); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED FastLED.show(); #endif } // Set a LED color (not yet visible) void setPixel(int Pixel, byte red, byte green, byte blue) { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.setPixelColor(Pixel, strip.Color(red, green, blue)); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED leds[Pixel].r = red; leds[Pixel].g = green; leds[Pixel].b = blue; #endif } // Set all LEDs to a given color and apply it (visible) void setAll(byte red, byte green, byte blue) { for(int i = 0; i < NUM_LEDS; i++ ) { setPixel(i, red, green, blue); } showStrip(); }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
7 hours ago | 13.15 KB
Analog GPUs: THE FUTURE
13 hours ago | 8.88 KB
Quotes I believe to be true.
13 hours ago | 0.16 KB
Die 7 wichtigsten Aktionen diese Woche
21 hours ago | 4.17 KB
Untitled
22 hours ago | 13.34 KB
Untitled
23 hours ago | 13.59 KB
VNC SCRIPT 2/2: autoinput.vbs
VBScript | 1 day ago | 0.23 KB
VNC SCRIPT 1/2: vncauto.bat
Batch | 1 day ago | 0.72 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!