Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // FastLED Setup
- #include "FastLED.h"
- #define LEDstrips 14
- #define LEDper 60
- #define LEDtype WS2813
- #define LEDcorr TypicalSMD5050
- #define LEDdither 255 //try 0 to reduce flickering
- uint8_t LEDbright = 15;
- CRGB leds[LEDstrips][LEDper];
- uint8_t seed;
- uint8_t hue;
- // MSGEQ7
- #include "MSGEQ7.h"
- #define EQ7pin A0
- #define EQ7reset PIN_B0
- #define EQ7strobe PIN_B1
- #define EQ7interval ReadsPerSecond(50)
- #define EQ7smooth true
- #define nz 30
- CMSGEQ7<EQ7smooth, EQ7reset, EQ7strobe, EQ7pin> MSGEQ7;
- int EQ7max[7];
- int EQ7reset[7];
- // Remote check IRLremote.h
- #include <IRremote.h>
- #define IRpin PIN_C0
- IRrecv irrecv(IRpin);
- decode_results results;
- int IRhold;
- void setup() {
- // Initialize LEDs
- FastLED.setMaxPowerInVoltsAndMilliamps(5,450); //play wit hthe order here
- FastLED.setBrightness(LEDbright);
- FastLED.setDither(LEDdither);
- FastLED.clear();
- FastLED.addLeds<LEDtype, PIN_C7>(leds[0], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_C6>(leds[1], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_C5>(leds[2], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_C4>(leds[3], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_C3>(leds[4], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_C2>(leds[5], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_C1>(leds[6], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F1>(leds[7], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F2>(leds[8], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F3>(leds[9], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F4>(leds[10], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F5>(leds[11], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F6>(leds[12], LEDper).setCorrection(LEDcorr);
- FastLED.addLeds<LEDtype, PIN_F7>(leds[13], LEDper).setCorrection(LEDcorr);
- FastLED.clear();
- FastLED.show(); // do I need a show after a clear?
- // Initialize other components & diagnostic
- irrecv.enableIRIn();
- Serial.begin(9600);
- MSGEQ7.begin();
- }
- void loop() { //could just move boot pattern here if it has an IR break in it
- remote();
- }
- void remote(){
- if (irrecv.decode(&results)) { //input might be cut off after receving first value, will need to store immediately if so
- if(results.value = 0XFFFFFF){
- results.value = IRhold;
- } else {
- IRhold = results.value;
- }
- Serial.println(results.value, HEX); // display the value
- switch(results.value){
- case 0xFF30CF: // "1"
- vizualiser(); //goto
- break;
- case 0xFF18E7: // "2"
- waterfall();
- break;
- case 0xFF7A85: // "3"
- rando();
- break;
- case 0xFF10EF: // "4"
- snow();
- break;
- case 0xFF38C7: // "5"
- frogger();
- break;
- case 0xFFA25D: // "Power"
- FastLED.clear();
- FastLED.show();
- remote();
- break;
- case 0xFFE01F: // "Down"
- LEDbright = LEDbright - 5;
- FastLED.setBrightness(LEDbright);
- FastLED.show();
- break;
- case 0xFF906F: // "Up"
- LEDbright = LEDbright + 5;
- FastLED.setBrightness(LEDbright);
- FastLED.show();
- break;
- }
- irrecv.resume(); // receive the next value
- }
- }
- void vizualiser(){
- bool newReading = MSGEQ7.read(EQ7interval); // Look for new reading
- if (newReading) {
- FastLED.clear();
- for(int s = 0; s < LEDstrips/2; s++){ // For each fq
- uint8_t fq = MSGEQ7.get(s); // Get reading
- fq = mapNoise(fq, nz, 255, 0, 255); // Reduce noise
- fq = map(fq, 0, 255, 0, LEDper); // Scale values to length of strips
- if(fq > EQ7max[s]) { // Rescale maximums
- EQ7max[s] = fq;
- } else {
- EQ7reset[s]++;
- if(EQ7reset[s] = 255){
- EQ7max[s] = fq;
- // EQ7reset++;
- }
- for(int l = 0; l < fq; l++){ // Write values
- leds[s][l].setHSV(hue+l*5, 255, 255);
- leds[13-s][l].setHSV(hue+l*5, 255, 255);
- }
- }
- }
- FastLED.show();
- hue++;
- }
- delay(30);
- }
- void snow(){
- for (int i=0; i<1000; i++){ // runs 3 times - better boot pattern? (fade?)
- for (int x=0; x<LEDstrips; x++){ //rows
- for (int y=0; y<LEDper; y++){ //columns
- leds[x][y] = CHSV( random8(), random8(), 255);
- }
- }
- FastLED.show();
- delay(); // adjust so change is visible
- }
- }
- void rando(){
- for (int i=0; i<1000; i++){ // runs 3 times - better boot pattern? (fade?)
- leds[rand(0, LEDstrips)][rand(0, LEDper)] = CHSV( random8(), random8(), rand(155,255));
- delay(1); // adjust so change is visible
- FastLED.show();
- }
- }
- void scan(){
- for (int leng=0; leng < LEDper; leng++){ //can make this a while loop, and make length proportional to delay
- for (int wide=0; wide < LEDstrips; wide++){
- leds[wide][leng] = CHSV(seed, rand(100,255), 255);
- }
- // FastLED.show();
- // delayMicroseconds(1);
- }
- seed++;
- FastLED.show();
- delay(300);
- }
- void waterfall(){
- int rowcount = 0;
- while (1){
- for (int row = 0; row < rowcount/10; row++){
- for (int col = 0; col < LEDstrips; col++){ // Write each row with start colour and a random saturation
- leds[col][row] = CHSV(hue + row*5, 255, 255); //random(155,255)
- }
- hue = hue + 1;
- }
- FastLED.show();
- delay(50);
- if(rowcount/10 < LEDper){rowcount = rowcount+1;}
- }
- }
- // Diagonal - this wont work, but it will be dope!
- void diagonal(){
- int rowpass = 0;
- int colpass = 0;
- int diagseed = random8();
- while (colpass < LEDstrips && rowpass < LEDper){
- for (int c = 0; c < colpass; c++){
- for (int r = 0; r < rowpass; r++){
- leds[r][c] = CHSV (diagseed++, 255, 255);
- FastLED.show();
- delay(1);
- }
- rowpass++;
- }
- colpass++;
- }
- }
- void spiral(int m, int n){
- int i, currRow = 0, currCol = 0;
- while (currRow < LEDstrips && currCol <LEDper) { //might have to define COL
- for (i = currCol; i < n; i++) { //print the first row normally
- leds[currRow][i] = CHSV (spiralseed, 255, LEDbright);
- seed++; // make sure this is kosher
- FastLED.show();
- // cout << spiral[currRow][i]<<" "; //replace with LED
- }
- currRow++; //point to next row
- for (i = currRow; i < m; ++i) { //Print the last column
- leds[i][n-1] = CHSV (spiralseed, 255, LEDbright);
- seed++;
- FastLED.show();
- // cout << spiral[i][n-1]<<" ";
- }
- n--; //set the n-1th column is current last column
- if ( currRow< m) { //when currRow is in the range, print the last row
- for (i = n-1; i >= currCol; --i) {
- leds[m-1][i] = CHSV (spiralseed, 255, LEDbright);
- seed++;
- FastLED.show();
- // cout << spiral[m-1][i]<<" ";
- }
- m--; //decrease the row range
- }
- if (currCol <n) { //when currCol is in the range, print the fist column
- for (i = m-1; i >= currRow; --i) {
- leds[i][currCol] = CHSV (spiralseed, 255, LEDbright);
- seed++;
- FastLED.show();
- // cout << spiral[i][currCol]<<" ";
- }
- currCol++;
- }
- }
- }
- void frogger(){
- for(int i = 0; i < 1000; i++){
- for(int col = 0; col < LEDstrips; col++){
- for(int row = 0; row <LEDper; row++){
- leds[col][row] = CHSV(seed*5*(1+(-2*col%2)), 255, 255); // negative is to alternate rows
- }
- }
- seed++;
- }
- for(int i = 0; i < 1000; i++){
- for(int row = 0; row < LEDper; row++){
- for(int col = 0; col < LEDstrips; col++){
- leds[col][row] = CHSV(
- }
- }
- }
- }
- /*
- void dispSpiral(int m, int n){
- int i, currRow = 0, currCol = 0;
- int spiralseed = random8();
- while (currRow < ROW && currCol <COL) { //might have to define COL
- for (i = currCol; i < n; i++) { //print the first row normally
- leds[curr row][i] = CHSV (spiralseed, 255, bright);
- spiralseed++; // make sure this is kosher
- FastLED.show();
- // cout << spiral[currRow][i]<<" "; //replace with LED
- }
- currRow++; //point to next row
- for (i = currRow; i < m; ++i) { //Print the last column
- leds[i][n-1] = CHSV (spiralseed, 255, bright);
- spiralseed++;
- FastLED.show();
- // cout << spiral[i][n-1]<<" ";
- }
- n--; //set the n-1th column is current last column
- if ( currRow< m) { //when currRow is in the range, print the last row
- for (i = n-1; i >= currCol; --i) {
- leds[m-1][i] = CHSV (spiralseed, 255, bright);
- spiralseed++;
- FastLED.show();
- // cout << spiral[m-1][i]<<" ";
- }
- m--; //decrease the row range
- }
- if (currCol <n) { //when currCol is in the range, print the fist column
- for (i = m-1; i >= currRow; --i) {
- leds[i][currcol] = CHSV (spiralseed, 255, bright);
- spiralseed++;
- FastLED.show();
- // cout << spiral[i][currCol]<<" ";
- }
- currCol++;
- }
- }
- }
- // Tasks
- Add fade to black shutdown/sleep
- Easing and Linear Interpolation functions
- leds[14][60] += leds[14][60]
- Put breaks
- Spiral in/out -> reverse?
- figure out fill rainbow
- Remove delay
- // one of these two will be more efficient
- fill_rainbow( &(leds[LEDstrips][LEDper]), LEDstrips * LEDper, 0); //Basic
- or
- seed = random8();
- For (int x=0; x<LEDstrips; x++){
- fill_rainbow( &(leds[x][]), LEDper, seed; //random is start value
- FastLED.show();
- delayMiliseconds(100);
- }
- // diagonal
- // do all on first row, adding 1, then do next row adding one
- for(int i=0; i{}
- leds[][] = CHSV
- // Timers
- void dispWarp() {
- unsigned long currentMillis1 = millis() % 20000;
- if(currentMillis1 < 10000) {
- int x = map(currentMillis1, 0, 9999, 0, 128);
- //turn on x number of LEDs
- }
- else {
- int x = map(currentMillis1, 10000, 19999, 128, 0);
- //turn on x number of LEDs
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement