Created
August 4, 2023 19:06
-
-
Save bshambaugh/b72a95cf70268b68a6377261d87bf6f5 to your computer and use it in GitHub Desktop.
sketch_used_for_sensorica_sign_08042023
This file contains hidden or 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
// video: https://www.youtube.com/watch?v=vH2QmrpCJuw | |
// code: https://www.tweaking4all.com/hardware/arduino/arduino-all-ledstrip-effects-in-one/ | |
#include <Adafruit_NeoPixel.h> | |
#ifdef __AVR__ | |
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket | |
#endif | |
// Which pin on the Arduino is connected to the NeoPixels? | |
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1 // white --> green wire | |
// VIN red wire | |
// GMD black wire | |
// How many NeoPixels are attached to the Arduino? | |
#define NUMPIXELS 135 // Popular NeoPixel ring size | |
#define SPEEDDELAY 0.02 | |
// When setting up the NeoPixel library, we tell it how many pixels, | |
// and which pin to use to send signals. Note that for older NeoPixel | |
// strips you might need to change the third parameter -- see the | |
// strandtest example for more information on possible values. | |
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | |
#define DELAYVAL 0 // Time (in milliseconds) to pause between pixels | |
void setup() { | |
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz. | |
// Any other board, you can remove this part (but no harm leaving it): | |
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) | |
clock_prescale_set(clock_div_1); | |
#endif | |
// END of Trinket-specific code. | |
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) | |
pixels.show(); // Initialize all pixels to 'off' | |
} | |
void loop() { | |
meteorRain(0xff,0x00,0x00,10, 64, true, 30); | |
} | |
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 < NUMPIXELS+NUMPIXELS; i++) { | |
// fade brightness all LEDs one step | |
for(int j=0; j<NUMPIXELS; j++) { | |
if( (!meteorRandomDecay) || (random(10)>5) ) { | |
fadeToBlack(j, meteorTrailDecay ); | |
} | |
} | |
// draw meteor | |
for(int j = 0; j < meteorSize; j++) { | |
if( ( i-j <NUMPIXELS) && (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 = pixels.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); | |
pixels.setPixelColor(ledNo, r,g,b); | |
#endif | |
#ifndef ADAFRUIT_NEOPIXEL_H | |
// FastLED | |
leds[ledNo].fadeToBlackBy( fadeValue ); | |
#endif | |
} | |
// Set a LED color (not yet visible) | |
void setPixel(int Pixel, byte red, byte green, byte blue) { | |
#ifdef ADAFRUIT_NEOPIXEL_H | |
// NeoPixel | |
pixels.setPixelColor(Pixel, pixels.Color(red, green, blue)); | |
#endif | |
#ifndef ADAFRUIT_NEOPIXEL_H | |
// FastLED | |
leds[Pixel].r = red; | |
leds[Pixel].g = green; | |
leds[Pixel].b = blue; | |
#endif | |
} | |
// Apply LED color changes | |
void showStrip() { | |
#ifdef ADAFRUIT_NEOPIXEL_H | |
// NeoPixel | |
pixels.show(); | |
#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 < NUMPIXELS; i++ ) { | |
setPixel(i, red, green, blue); | |
} | |
showStrip(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the old sketch that did not work:
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// Released under the GPLv3 license to match the rest of the
// Adafruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 135 // Popular NeoPixel ring size
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 0 // Time (in milliseconds) to pause between pixels
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(AVR_ATtiny85) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop() {
// The first NeoPixel in a strand is #0, second is 1, all the way up()
// to the count of pixels minus one.
int pulseLength = 6;
int k = 0; //k = 1 to NUMPIXELS -1
for(int k=0; k<NUMPIXELS; k++) {
pixels.clear(); // Set all pixel colors to 'off'
for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
// delay(DELAYVAL); // Pause before next pass through loop
}
delay(DELAYVAL);
}
}