Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 6
- #define ANALOGPIN A2
- #define COLOR_ORDER GRB
- #define CHIPSET WS2811
- #define BRIGHTNESS 64
- #define FRAMES_PER_SECOND 120
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- #define MAX_DIMENSION ((kMatrixWidth > kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
- // Params for width and height
- const uint8_t kMatrixWidth = 7;
- const uint8_t kMatrixHeight = 14;
- // Param for different pixel layouts
- const bool kMatrixSerpentineLayout = false;
- const bool kMatrixVertical = true;
- uint8_t gHue = 0;
- uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
- uint16_t value;
- uint16_t XY( uint8_t x, uint8_t y)
- {
- uint16_t i;
- if( kMatrixSerpentineLayout == false) {
- if (kMatrixVertical == false) {
- i = (y * kMatrixWidth) + x;
- } else {
- i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
- }
- }
- if( kMatrixSerpentineLayout == true) {
- if (kMatrixVertical == false) {
- if( y & 0x01) {
- // Odd rows run backwards
- uint8_t reverseX = (kMatrixWidth - 1) - x;
- i = (y * kMatrixWidth) + reverseX;
- } else {
- // Even rows run forwards
- i = (y * kMatrixWidth) + x;
- }
- } else { // vertical positioning
- if ( x & 0x01) {
- i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
- } else {
- i = kMatrixHeight * (kMatrixWidth - x) - (y+1);
- }
- }
- }
- return i;
- }
- #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
- CRGB leds_plus_safety_pixel[ NUM_LEDS + 1];
- CRGB* const leds( leds_plus_safety_pixel + 1);
- typedef void (*SimplePatternList[])();
- uint16_t XYsafe( uint8_t x, uint8_t y)
- {
- if( x >= kMatrixWidth) return -1;
- if( y >= kMatrixHeight) return -1;
- return XY(x,y);
- }
- SimplePatternList gPatterns = {
- test
- };
- void loop()
- {
- gPatterns[gCurrentPatternNumber]();
- // send the 'leds' array out to the actual LED strip
- FastLED.show();
- // insert a delay to keep the framerate modest
- FastLED.delay(1000/FRAMES_PER_SECOND);
- // do some periodic updates
- EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
- EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
- }
- void nextPattern()
- {
- // add one to the current pattern number, and wrap around at the end
- gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
- }
- void setup() {
- FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
- FastLED.setBrightness( BRIGHTNESS );
- Serial.begin(9600);
- }
- void test() {
- int V = read_pot();
- for (int x = 0; x < kMatrixWidth; x++){
- for (int y = 0; y < kMatrixHeight; y++){
- leds[XY(x,y)] = CHSV(160,255, V);
- FastLED.show();
- delay(20);
- }
- }
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- FastLED.show();
- }
- int read_pot() //LINEAR POT WORKS BEST
- {
- value = analogRead(ANALOGPIN);
- FastLED.setBrightness(value/4);
- Serial.print("Pot Value "); Serial.println(value/4);
- return(value/4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement