/ Resin_table_circuitplayground_modes / Resin_table_circuitplayground_modes.ino
Resin_table_circuitplayground_modes.ino
  1  // SPDX-FileCopyrightText: 2013 FastLED
  2  // SPDX-FileCopyrightText: 2018 Erin St Blaine for Adafruit Industries
  3  //
  4  // SPDX-License-Identifier: MIT
  5  
  6  // Code by Erin St Blaine for Adafruit.com, based on FastLED animations by Mark Kriegsman
  7  
  8  #include <Adafruit_CircuitPlayground.h>
  9  #include <FastLED.h>
 10  
 11  // tell FastLED all about the Circuit Playground's layout
 12  
 13  #define DATA_PIN     A1    //LED data on pin A1
 14  #define NUM_LEDS    200   // total number of LEDs in your strip
 15  #define COLOR_ORDER GRB  //  color order -- change this if your colors are coming out wrong
 16  
 17  uint8_t brightness = 150;  // Set brightness level
 18  
 19  int STEPS = 6;  //makes the rainbow colors more or less spread out
 20  int NUM_MODES = 5;  // change this number if you add or subtract modes
 21  int CYCLETIME = 60;  // number of seconds on each mode, for mode cycling
 22  
 23  CRGB leds[NUM_LEDS];      // set up an LED array
 24  
 25  CRGBPalette16 currentPalette;
 26  TBlendType    currentBlending;
 27  
 28  int ledMode = 0;       //Initial mode 
 29  bool leftButtonPressed;
 30  bool rightButtonPressed;
 31  
 32  
 33  // SETUP -----------------------------------------------------
 34  void setup() {
 35    Serial.begin(57600);
 36    CircuitPlayground.begin();
 37    FastLED.addLeds<WS2812B, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); // Use this line if using neopixels
 38    currentBlending = LINEARBLEND;
 39    set_max_power_in_volts_and_milliamps(5, 5000);               // FastLED 2.1 Power management set at 5V, 5000mA
 40  
 41    
 42  }
 43  
 44  void loop()  {
 45  
 46    leftButtonPressed = CircuitPlayground.leftButton();
 47    rightButtonPressed = CircuitPlayground.rightButton();
 48  
 49    if (leftButtonPressed) {  //left button cycles through modes
 50      clearpixels(); 
 51      ledMode=ledMode+1;
 52      delay(300);
 53      if (ledMode > NUM_MODES){
 54      ledMode=0;
 55       }
 56    }
 57      if (rightButtonPressed) {  // on off button
 58      ledMode=99;
 59    
 60      }
 61    
 62   switch (ledMode) {
 63         case 0: modeCycle(); break;
 64         case 1: currentPalette = RainbowColors_p; rainbow(); break;
 65         case 2: currentPalette = OceanColors_p; rainbow(); break;                    
 66         case 3: currentPalette = LavaColors_p; rainbow(); break;   
 67         case 4: currentPalette = ForestColors_p; rainbow(); break;
 68         case 5: currentPalette = PartyColors_p; rainbow(); break;
 69         case 99: clearpixels(); break;
 70         
 71  }
 72  }
 73  void clearpixels()
 74  {
 75    CircuitPlayground.clearPixels();
 76     for( int i = 0; i < NUM_LEDS; i++) {
 77     leds[i]= CRGB::Black;
 78      }
 79     FastLED.show();
 80  }
 81  
 82  void rainbow()
 83  {
 84    
 85    static uint8_t startIndex = 0;
 86    startIndex = startIndex + 1; /* motion speed */
 87  
 88    FillLEDsFromPaletteColors( startIndex);
 89  
 90    FastLED.show();
 91    FastLED.delay(20);
 92    
 93    }
 94  
 95  //this bit is in every palette mode, needs to be in there just once
 96  void FillLEDsFromPaletteColors( uint8_t colorIndex)
 97  { 
 98    for( int i = 0; i < NUM_LEDS; i++) {
 99      leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
100      colorIndex += STEPS;
101    }
102  }
103  
104  
105  int cycleMode=0;
106  
107  void modeCycle()
108  {
109     switch (cycleMode) {
110         case 0: currentPalette = RainbowColors_p; rainbow(); break;
111         case 1: currentPalette = OceanColors_p; rainbow(); break;                    
112         case 2: currentPalette = LavaColors_p; rainbow(); break;   
113         case 3: currentPalette = ForestColors_p; rainbow(); break;
114         case 4: currentPalette = PartyColors_p; rainbow(); break;
115         case 5: cycleMode=0; break;
116  }
117  
118     EVERY_N_SECONDS(CYCLETIME) {
119      cycleMode++;
120     }
121     
122  }