Advertisement
uwezi

20210114_attiny85_fastled

Jan 14th, 2021
1,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Arduino.h>
  2. /**************************************************
  3.  *
  4.  *   5/A0 PB5 reset |1  8| Vcc
  5.  *   3/A3 PB3       |2  7| sck  PB2  2/A1
  6.  *   4/A2 PB2       |3  6| miso PB1  1    
  7.  *              GND |4  5| mosi PB0  0    
  8.  * ATtiny85
  9.  *
  10.  **************************************************/
  11. #include <FastLED.h>
  12.  
  13. #define LED_PIN     0
  14. #define COLOR_ORDER RGB
  15. #define CHIPSET     WS2811
  16. #define NUM_LEDS    1
  17.  
  18. CRGB leds[NUM_LEDS];
  19. CRGBPalette16 currentPalette;
  20. TBlendType    currentBlending;
  21.  
  22. void setup()
  23. {
  24.   delay(500); // sanity delay
  25.   PORTB = 0b00000110; // pull-up on PB2 PB1
  26.   currentPalette = RainbowColors_p;
  27.   FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  28. }
  29.  
  30. uint8_t i=0;
  31.  
  32. void loop()
  33. {
  34.   uint16_t pot1, pot2;
  35.   uint8_t  mode;
  36.  
  37.   pot1 = analogRead(3);
  38.   pot2 = analogRead(2);
  39.  
  40.   // switch on PB2 PB1
  41.   mode = (PINB & 0b00000110) >> 1;
  42.   switch (mode)
  43.   {
  44.   case 0: // hue and saturation
  45.     leds[0] = CHSV( pot1/4, pot2/4, 255 );
  46.     break;
  47.   case 1: // sweep intensity
  48.     leds[0] = CHSV( pot1/4, 255, cubicwave8(i));
  49.     break;
  50.   case 2: // sweep saturation
  51.     leds[0] = CHSV( pot1/4, cubicwave8(i), 255);
  52.     break;
  53.   case 3:
  54.     switch (pot1/128)
  55.     {
  56.     case 0:
  57.       currentPalette = RainbowColors_p;        
  58.       currentBlending = LINEARBLEND;
  59.       break;
  60.     case 1:
  61.       currentPalette = RainbowStripeColors_p;        
  62.       currentBlending = LINEARBLEND;
  63.       pot2 = 1024+pot2*8;
  64.       break;
  65.     case 2:
  66.       currentPalette = RainbowStripeColors_p;        
  67.       currentBlending = LINEARBLEND;
  68.       break;
  69.     case 3:
  70.       currentPalette = CloudColors_p;        
  71.       currentBlending = LINEARBLEND;
  72.       break;
  73.     case 4:
  74.       currentPalette = PartyColors_p;        
  75.       currentBlending = LINEARBLEND;
  76.       break;
  77.     case 5:
  78.       currentPalette = OceanColors_p;        
  79.       currentBlending = LINEARBLEND;
  80.       break;
  81.     case 6:
  82.       currentPalette = LavaColors_p;        
  83.       currentBlending = LINEARBLEND;
  84.       break;
  85.     case 7:
  86.       currentPalette = ForestColors_p;        
  87.       currentBlending = LINEARBLEND;
  88.       break;
  89.     default:
  90.       break;
  91.     }
  92.  
  93.     leds[0] = ColorFromPalette( currentPalette, i, 255, currentBlending);
  94.     break;
  95.  
  96.   default:
  97.     break;
  98.   }
  99.   i++;
  100.  
  101.   FastLED.show(); // display this frame
  102.   if (mode != 0)
  103.   {
  104.     FastLED.delay(pot2/8);
  105.   }
  106.   else
  107.   {
  108.     FastLED.delay(50);
  109.   }
  110.  
  111. }
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement