Skip to content

Instantly share code, notes, and snippets.

@atuline
Created July 15, 2018 14:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atuline/c35657231ec5b711a306855364e426b3 to your computer and use it in GitHub Desktop.
Save atuline/c35657231ec5b711a306855364e426b3 to your computer and use it in GitHub Desktop.
/* inoise8_car
*
* By: Andrew Tuline
*
* Date: July, 2018
*
* A simple 8 bit routine that moves along a NOISE plane.
*
* This uses a fixed palette.
*
*/
#include "FastLED.h" // FastLED library.
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
// Fixed definitions cannot change on the fly.
#define LED_DT 12 // Data pin to connect to the strip.
#define LED_CK 11 // Clock pin for WS2801 or APA102.
#define COLOR_ORDER BGR // It's GRB for WS2812 and BGR for APA102.
#define LED_TYPE APA102 // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit.
#define NUM_LEDS 60 // Number of LED's.
uint8_t max_bright = 255; // Overall brightness value.
CRGB leds[NUM_LEDS];
CRGBPalette16 currentPalette;
TBlendType currentBlending = LINEARBLEND;
void setup() {
Serial.begin(57600); // Initialize serial port for debugging.
delay(1000); // Startup delay.
LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER, DATA_RATE_MHZ(12)>(leds, NUM_LEDS); // Use this for WS2801 or APA102
// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER, DATA_RATE_MHZ(12)>(leds, NUM_LEDS); // Use this for WS2812
currentPalette = ForestColors_p;
FastLED.setBrightness(max_bright); // Set the brightness.
set_max_power_in_volts_and_milliamps(5, 1000); // FastLED Power management set at 5V, 500mA.
} // setup()
void loop() {
EVERY_N_MILLISECONDS(1000) {
// Serial.println(LEDS.getFPS()); // Checking our frame rate.
}
EVERY_N_MILLISECONDS(10) {
inoise8_car(); // We don't need to run this continuously, so let's slow it down.
}
FastLED.show();
} // loop()
void inoise8_car() {
uint8_t speed = 5;
uint8_t scale = 15; // Higher value = More color changes.
uint8_t noise_hue = 0; // Resultant hue that gets selected from palette
uint8_t noise_bright = 0; // Resultant brightness for LED that's selected from palette
static uint16_t x_val = 0; // Current X location
static uint16_t y_val = 0; // Current Y location
x_val = x_val+speed;
y_val = y_val+speed; // We move along the Y plane.
for (uint16_t i = 0; i < NUM_LEDS; i++) { // Hey, this supports more than my standard 255 LED's.
uint16_t xlocn = x_val + i * scale; // Let's scale out.
uint16_t ylocn = y_val + i * scale;
noise_hue = inoise8(xlocn, ylocn); // Get the hue value at the current location.
noise_bright = inoise8(xlocn+1000, ylocn+1000); // Get brightness value from a different location than the hue value.
leds[i] = ColorFromPalette(currentPalette, noise_hue, noise_bright, currentBlending); // With those values, look up the 8 bit colour palette value and assign it to the current LED.
}
} // inoise8_car()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment