Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- //Tell it how many leds are in the strip. AndyMark's 2.5 meter strip has 80 leds
- #define NUM_LEDS 64
- // This is an array of leds. One item for each led in your strip.
- CRGB leds[NUM_LEDS];
- //CSK 3/17/2014 I moved these to pins that don't conflict with Ethernet functions in case you want to control LEDs via Ethernet
- #define DATA_PIN 2 //Green wire from AM-2640's power connector
- // Clock pin SPI
- #define CLOCK_PIN 3 //Blue wire from AM-2640's power connector
- #define MAX_BRIGHTNESS 100
- String incomingString = "rainbow"; // for incoming serial data
- String oldAnim;
- //This function is used to setup things like pins, Serial ports etc.
- //Here we specify which chipset our LEDs run off of by our choice of config function
- void setup()
- {
- Serial.begin(9600);
- Serial.setTimeout(10);
- //attachInterrupt(digitalPinToInterrupt(interruptPin), serial_read, HIGH);
- Serial.println("[Warning]: Warnung vor photosensitiven Anfällen !!!");
- Serial.println("[INFO]: Animationen rainbow, cylon, color_chase, missing_dot_chase, test2, police");
- //***This is the chipset in the AM-2640 LED strip***
- //CSK 3/17/2013 Changed to this function to allow direct data and clock pin specification
- FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
- }
- void loop()
- {
- //This is kind of Arduino's equivalent to Main() in a standard C program
- //This, as the name implies, loops endlessly.
- //https://code.google.com/p/fastspi/wiki/CRGBreference
- //CSK 3/20/2014 I added a rainbow function just for grins
- // send data only when you receive data:
- if (Serial.available() > 0) {
- // read the incoming byte:
- incomingString = Serial.readString();
- // say what you got:
- Serial.println("[Serial][in]: Animation '" + incomingString + "' wird gestartet");
- }
- if(incomingString == "rainbow"){
- rainbow(20);
- }
- else if(incomingString == "cylon"){
- cylon(CRGB::Aqua,25 ,15);
- }
- else if(incomingString == "color_chase"){
- color_chase(CRGB::Cyan, 15);
- }
- else if(incomingString == "missing_dot_chase"){
- missing_dot_chase(0x3000cc, 20);
- }
- else if(incomingString == "test2"){
- test2(80);
- }
- else if(incomingString == "police"){
- police(150);
- }
- }
- void printAnimation(String text){
- Serial.println("[Animation]: " + text);
- return;
- }
- void police(uint8_t wait){
- CRGB left = CRGB::Red;
- CRGB right = CRGB::Blue;
- FastLED.setBrightness(MAX_BRIGHTNESS);
- if(oldAnim != "police"){
- printAnimation("police");
- }
- oldAnim = "police";
- FastLED.clear();
- for(int led_nummer = 0; led_nummer < NUM_LEDS/2; led_nummer++){
- leds[led_nummer] = left;
- }
- FastLED.show();
- FastLED.clear();
- delay(wait/2);
- for(int led_nummer = 0; led_nummer < NUM_LEDS/2; led_nummer++){
- leds[led_nummer] = CRGB::Black;
- }
- FastLED.show();
- FastLED.clear();
- delay(wait/2);
- for(int led_nummer = 0; led_nummer < NUM_LEDS/2; led_nummer++){
- leds[led_nummer] = left;
- }
- FastLED.show();
- delay(wait/2);
- for(int led_nummer = 0; led_nummer < NUM_LEDS/2; led_nummer++){
- leds[led_nummer] = CRGB::Black;
- }
- FastLED.show();
- FastLED.clear();
- delay(wait/2);
- for(int led_nummer = 0; led_nummer < NUM_LEDS/2; led_nummer++){
- leds[led_nummer] = left;
- }
- FastLED.show();
- ///////////////////
- delay(wait);
- ///////////////////
- FastLED.clear();
- for(int led_nummer = NUM_LEDS/2; led_nummer < NUM_LEDS; led_nummer++){
- leds[led_nummer] = right;
- }
- FastLED.show();
- FastLED.clear();
- delay(wait/2);
- for(int led_nummer = NUM_LEDS/2; led_nummer < NUM_LEDS; led_nummer++){
- leds[led_nummer] = CRGB::Black;
- }
- FastLED.show();
- FastLED.clear();
- delay(wait/2);
- for(int led_nummer = NUM_LEDS/2; led_nummer < NUM_LEDS; led_nummer++){
- leds[led_nummer] = right;
- }
- FastLED.show();
- delay(wait/2);
- for(int led_nummer = NUM_LEDS/2; led_nummer < NUM_LEDS; led_nummer++){
- leds[led_nummer] = CRGB::Black;
- }
- FastLED.show();
- FastLED.clear();
- delay(wait/2);
- for(int led_nummer = NUM_LEDS/2; led_nummer < NUM_LEDS; led_nummer++){
- leds[led_nummer] = right;
- }
- FastLED.show();
- delay(wait);
- }
- //These are the functions we have defined to do chase patterns. They are actually called inside the loop() above
- //They are meant to demonstrate things such as setting LED colors, controlling brightness
- void color_chase(uint32_t color, uint8_t wait){
- if(oldAnim != "color_chase"){
- printAnimation("color_chase");
- }
- oldAnim = "color_chase";
- //clear() turns all LEDs off
- FastLED.clear();
- //The brightness ranges from 0-255
- //Sets brightness for all LEDS at once
- FastLED.setBrightness(MAX_BRIGHTNESS);
- // Move a single led
- for(int led_number = 0; led_number < NUM_LEDS; led_number++)
- {
- // Turn our current led ON, then show the leds
- leds[led_number] = color;
- // Show the leds (only one of which is has a color set, from above
- // Show turns actually turns on the LEDs
- FastLED.show();
- // Wait a little bit
- delay(wait);
- // Turn our current led back to black for the next loop around
- leds[led_number] = CRGB::Black;
- }
- return;
- }
- void test2(uint8_t wait){
- if(oldAnim != "test2"){
- printAnimation("test2");
- }
- oldAnim = "test2";
- for(int led_number = 0; led_number < NUM_LEDS; led_number++)
- {
- FastLED.clear();
- randomSeed(millis());
- //Eine LED
- FastLED.setBrightness(random(255));
- leds[random(NUM_LEDS)] = CRGB::Aqua; //CRGB(random(255),random(255),random(255));
- delay(wait);
- FastLED.show();
- }
- //delay(wait);
- }
- void test(uint8_t wait)
- {
- if(oldAnim != "test"){
- printAnimation("test");
- }
- oldAnim = "test";
- randomSeed(millis());
- FastLED.clear();
- //Eine LED
- FastLED.setBrightness(random(255));
- leds[random(NUM_LEDS)] = CRGB(random(255),random(255),random(255));
- //Zweite LED
- FastLED.setBrightness(random(255));
- leds[random(NUM_LEDS)] = CRGB(random(255),random(255),random(255));
- //Dritte LED
- FastLED.setBrightness(random(255));
- leds[random(NUM_LEDS)] = CRGB(random(255),random(255),random(255));
- //Vierte LED
- FastLED.setBrightness(random(255));
- leds[random(NUM_LEDS)] = CRGB(random(255),random(255),random(255));
- FastLED.show();
- delay(wait);
- }
- //Move an "empty" dot down the strip
- void missing_dot_chase(uint32_t color, uint8_t wait)
- {
- if(oldAnim != "missing_dot_chase"){
- printAnimation("missing_dot_chase");
- }
- oldAnim = "missing_dot_chase";
- //Step thru some brightness levels from max to 10. led_brightness/=2 is a cryptic shorthand way of saying led_brightness = led_brightness/2
- for (int led_brightness = MAX_BRIGHTNESS; led_brightness > 10; led_brightness/=2)
- {
- FastLED.setBrightness(led_brightness);
- // Start by turning all pixels on:
- //for(int led_number = 0; led_number < NUM_LEDS; led_number++) leds[led_number] = color;
- //https://github.com/FastLED/FastLED/wiki/Controlling-leds
- fill_solid(leds, NUM_LEDS, color);
- // Then display one pixel at a time:
- for(int led_number = 0; led_number < NUM_LEDS; led_number++)
- {
- leds[led_number] = CRGB::Black; // Set new pixel 'off'
- if( led_number > 0 && led_number < NUM_LEDS)
- {
- leds[led_number-1] = color; // Set previous pixel 'on'
- }
- FastLED.show();
- delay(wait);
- }
- }
- return;
- }
- //Cylon - LED sweeps back and forth, with the color, delay and number of cycles of your choice
- void cylon(CRGB color, uint16_t wait, uint8_t number_of_cycles)
- {
- if(oldAnim != "cylon"){
- printAnimation("cylon");
- }
- oldAnim = "cylon";
- FastLED.setBrightness(255);
- for (uint8_t times = 0; times<=number_of_cycles; times++)
- {
- // Make it look like one LED is moving in one direction
- for(int led_number = 0; led_number < NUM_LEDS; led_number++)
- {
- //Apply the color that was passed into the function
- leds[led_number] = color;
- //Actually turn on the LED we just set
- FastLED.show();
- // Turn it back off
- leds[led_number] = CRGB::Black;
- // Pause before "going" to next LED
- delay(wait);
- }
- // Now "move" the LED the other direction
- for(int led_number = NUM_LEDS-1; led_number >= 0; led_number--)
- {
- //Apply the color that was passed into the function
- leds[led_number] = color;
- //Actually turn on the LED we just set
- FastLED.show();
- // Turn it back off
- leds[led_number] = CRGB::Black;
- // Pause before "going" to next LED
- delay(wait);
- }
- }
- return;
- }
- void rainbow(uint8_t wait)
- {
- if(oldAnim != "rainbow"){
- printAnimation("rainbow");
- }
- oldAnim = "rainbow";
- uint16_t hue;
- FastLED.clear();
- for(hue=10; hue<255*3; hue++)
- {
- fill_rainbow( &(leds[0]), NUM_LEDS /*led count*/, hue /*starting hue*/);
- FastLED.show();
- delay(wait);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement