Показано с 1 по 1 из 1
  1. #1
    Администратор Аватар для Chip
    Регистрация
    08.06.2007
    Возраст
    54
    Сообщений
    13,376
    Вес репутации
    10

    По умолчанию Бегущие огни на Digispark

    Бегущие огни на Digispark и WS2812B. Можно так же применить в автомобиле, подправив предварительно скетч
    На базе этой схемы можно сделать красивые, динамические поворотники
    Скетч, схема и обсуждение здесь http://cyber-place.ru/showthread.php?t=2774

    Видео


    Схема
    Нажмите на изображение для увеличения. 

Название:	digispark.png 
Просмотров:	260 
Размер:	104.2 Кб 
ID:	19347

    Скетч для Digispark
    PHP код:
    #include <Adafruit_NeoPixel.h>
    #define PIN 1
    #define NUM_PIX 24
    Adafruit_NeoPixel strip Adafruit_NeoPixel(NUM_PIXPINNEO_GRB NEO_KHZ800);

    void setup() 
    {
      
    randomSeed(analogRead(0));
      
    strip.begin();
      
    strip.show(); // Инициализация , все светодиоды выключены
    }

    void loop() 
    {
      
    towards(430);

        
    rgbFade(002555); // синий
        
    rgbFade(002555); // синий
        
    rgbFade(002555); // синий
     
       
    runPix(1010);
      
      
    colorWipe(strip.Color(00255), 50); // Blue
      
      
    theaterChase(strip.Color(00255), 50); // Blue

    //  rainbow(20);
    //  rainbowCycle(20);
    //  theaterChaseRainbow(50);
      
      
    flame(255150); 
    }

    //бегущий пиксель
    void runPix(uint8_t ciclesuint8_t wait
    {
      
    strip.setBrightness(255);
      for(
    int c=0c<ciclesc++)
      {  
       for(
    int i=0i<strip.numPixels(); i++)
       {
        
    strip.setPixelColor(istrip.Color(0,0,255));
        
    strip.show(); 
        
    strip.setPixelColor(istrip.Color(0,0,0));
        
    delay(wait);
       }
      }
    }

    //эффект огня/пламени
    void flame(uint8_t ciclesuint8_t wait)
    {
     
    strip.setBrightness(255);
     for(
    int i=0i<ciclesi++)
      { 
       for(
    int i=0i<strip.numPixels(); i++)
       {
        
    strip.setPixelColor(istrip.Color(0random(045), random(150254) ));
       }
        
    strip.setBrightness(random(151,254));
        
    strip.show(); // This sends the updated pixel color to the hardware.
        
    delay(random(wait));
     }
    }  

    // плавное наростание яркости любого цвета
    void rgbFade(uint8_t reduint8_t greenuint8_t blueuint8_t wait
    {
      
    strip.setBrightness(255);
      for(
    uint8_t b=0b<255b++) 
      {
         for(
    uint8_t i=0i<strip.numPixels(); i++) 
         {
            
    strip.setPixelColor(ired b/255green b/255blue b/255);
         }
         
    strip.show();
         
    delay(wait);
      }
    delay(300);

      for(
    uint8_t b=2550b--) 
      {
         for(
    uint8_t i 0strip.numPixels(); i++) 
         {
            
    strip.setPixelColor(ired b/255green b/255blue b/255);
         }
         
    strip.show();
         
    delay(wait);
      }
       
    strip.setBrightness(0);
       
    strip.show();
      
    delay(200);
    }

    // бегущие на встречу пиксели
    void towards
    uint8_t ciclesuint8_t wait 
    {
      for(
    byte c=0c<ciclesc++) 
      {
        for(
    byte i=0i<strip.numPixels(); i++) 
        {
          
    strip.setPixelColor(istrip.Color(0,0,255));
          
    strip.setPixelColor(strip.numPixels()-istrip.Color(0,0,255));
          
    strip.show();
          
    strip.setPixelColor(istrip.Color(0,0,0));
          
    strip.setPixelColor(strip.numPixels()-istrip.Color(0,0,0));
         
    delay(wait);
        } 
      }
    }

    // //заполнение ленты пиксель за пикселем
    void colorWipe(uint32_t cuint8_t wait
    {
      
    strip.setBrightness(255);
      for(
    uint16_t i=0i<strip.numPixels(); i++) 
      {
          
    strip.setPixelColor(ic);
          
    strip.show();
          
    delay(wait);
      }
    }

    //радуга
    void rainbow(uint8_t wait
    {
      
    uint16_t ij;
      
    strip.setBrightness(255);
      for(
    j=0j<256j++) {
        for(
    i=0i<strip.numPixels(); i++) {
          
    strip.setPixelColor(iWheel((i+j) & 255));
        }
        
    strip.show();
        
    delay(wait);
      }
    }

    // Slightly different, this makes the rainbow equally distributed throughout
    void rainbowCycle(uint8_t wait
    {
      
    uint16_t ij;

    strip.setBrightness(255);
      for(
    j=0j<256*5j++) { // 5 cycles of all colors on wheel
        
    for(i=0istrip.numPixels(); i++) {
          
    strip.setPixelColor(iWheel(((256 strip.numPixels()) + j) & 255));
        }
        
    strip.show();
        
    delay(wait);
      }
    }

    //Theatre-style crawling lights.
    void theaterChase(uint32_t cuint8_t wait
    {
     
    strip.setBrightness(255); 
      for (
    int j=0j<10j++) {  //do 10 cycles of chasing
        
    for (int q=03q++) {
          for (
    int i=0strip.numPixels(); i=i+3) {
            
    strip.setPixelColor(i+qc);    //turn every third pixel on
          
    }
          
    strip.show();
         
          
    delay(wait);
         
          for (
    int i=0strip.numPixels(); i=i+3) {
            
    strip.setPixelColor(i+q0);        //turn every third pixel off
          
    }
        }
      }
    }

    //Theatre-style crawling lights with rainbow effect
    void theaterChaseRainbow(uint8_t wait
    {
    strip.setBrightness(255);
      for (
    int j=0256j++) {     // cycle all 256 colors in the wheel
        
    for (int q=03q++) {
            for (
    int i=0strip.numPixels(); i=i+3) {
              
    strip.setPixelColor(i+qWheel( (i+j) % 255));    //turn every third pixel on
            
    }
            
    strip.show();
           
            
    delay(wait);
           
            for (
    int i=0strip.numPixels(); i=i+3) {
              
    strip.setPixelColor(i+q0);        //turn every third pixel off
            
    }
        }
      }
    }

    // Input a value 0 to 255 to get a color value.
    // The colours are a transition r - g - b - back to r.
    uint32_t Wheel(byte WheelPos
    {
      
    strip.setBrightness(255);
      
    WheelPos 255 WheelPos;
      if(
    WheelPos 85) {
       return 
    strip.Color(255 WheelPos 30WheelPos 3);
      } else if(
    WheelPos 170) {
        
    WheelPos -= 85;
       return 
    strip.Color(0WheelPos 3255 WheelPos 3);
      } else {
       
    WheelPos -= 170;
       return 
    strip.Color(WheelPos 3255 WheelPos 30);
      }

    Последний раз редактировалось Chip; 15.03.2018 в 19:07.

Информация о теме

Пользователи, просматривающие эту тему

Эту тему просматривают: 1 (пользователей: 0 , гостей: 1)

Ваши права

  • Вы не можете создавать новые темы
  • Вы не можете отвечать в темах
  • Вы не можете прикреплять вложения
  • Вы не можете редактировать свои сообщения
  •