Skip to content

Instantly share code, notes, and snippets.

@nervusvagus
Last active August 8, 2018 20:20
Show Gist options
  • Save nervusvagus/a5e38866606781491074c2f02c6af853 to your computer and use it in GitHub Desktop.
Save nervusvagus/a5e38866606781491074c2f02c6af853 to your computer and use it in GitHub Desktop.
Moving simple patterns
//***************************************************************
// Moving simple pattern
// It will wrap around, and the direction can be reversed.
// This is done a bit different then you might expect as I'm
// filling a seperate CRGB array with the custom colors/pattern
// just once in setup(). Then coping that into the main leds
// array as needed when moving it around. There are certanly
// fancier ways to do this, but this gets a simple pattern like
// going quickly.
//
// Marc Miller, Aug 2018
//***************************************************************
#include "FastLED.h"
#define LED_TYPE WS2812B
#define DATA_PIN 11
#define CLOCK_PIN 13
#define NUM_LEDS 255
#define COLOR_ORDER GRB
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS]; //what gets displayed
CRGB base[NUM_LEDS];
int8_t delta = 1; // 1 or -1. (Negative value reverses direction.)
#define RATE 20 //how fast patern moves (smaller number is faster)
uint8_t pos = 0; // position along strip
uint8_t pos2 = 0;
//---------------------------------------------------------------
void setup() {
Serial.begin(57600); // Allows serial monitor output (check your baud rate)
delay(3000); // Startup delay
FastLED.addLeds<WS2812, 10, GRB>(leds, 300);
FastLED.setBrightness(BRIGHTNESS);
//setup custom colors/pattern in the base array
} //end setup
// base[3] = base[4] = base[5] = CHSV( 60, 100, 100); gri renk wth???
//---------------------------------------------------------------
void loop() {
JellyFishBase();
JellyFishPattern();
} //end MAIN LOOP
void JellyFishBase(){
fill_solid( base, NUM_LEDS, CRGB::Red); // base color
base[0] = CRGB::Blue;
base[1] = base[2] = base[3] = base[4] = base[5]=base[6] = base[7] = CRGB::Green;
base[8] = base[9] = CHSV( 90, 255, 255); //custom colors //custom colors
base[10] = base[11] = base[12] = base[13] = base[14] = base[15] = CHSV( 60, 255, 255); //custom colors
base[16] = base[17] = CHSV( 30, 255, 255);
for (uint8_t i = 18; i < 92; i++) {
base[i] =CRGB::Red;
}
/*
base[18] = base[19] = base[20] = base[21] = base[22] = base[23] = base[24] = base[25] = base[26] = base[27] = base[28] = base[29] = base[30] = base[31] = CRGB::Red;*/
base[93] = CRGB::Blue;
base[94] = base[95] = base[96] = base[97] = base[98]=base[99] = CRGB::Green;
base[100] = base[101] = CHSV( 90, 255, 255); //custom colors //custom colors
base[102] = base[103] = base[104] = base[105] = base[106] = base[107] = base[108] = CHSV( 60, 255, 255); //custom colors
base[109] = base[110] = CHSV( 30, 255, 255);
}
void JellyFishPattern()
{
EVERY_N_MILLISECONDS(RATE) {
for (uint8_t i = 0; i < NUM_LEDS; i++) {
// leds[i+1] = base[i];
leds[mod8(pos + delta + i, NUM_LEDS)] = base[i];
/// (pos + delta + i) % 255 ( uint8_t a, uint8_t m ) Calculate the remainder of one unsigned 8-bit value divided by anoter, aka A % M. Implemented by repeated subtraction, which is very compact, and very fast if A is 'probably' less than M. If A is a large multiple of M, the
// Serial.print("mod8(pos + delta + i, NUM_LEDS): "); Serial.print(mod8(pos + delta + i, NUM_LEDS)); Serial.print(" i "); Serial.print(i); Serial.print(" i+1 "); Serial.println(i+1);
}
FastLED.show(); // Display the pixels.
pos = pos + delta;
Serial.print("pos: "); Serial.println(pos);
}} //end EVERY_N}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment