Created
November 26, 2017 13:11
-
-
Save gibbedy/5650194fc86308b98e2ab03fac782af5 to your computer and use it in GitHub Desktop.
This is how I think I'm zeroing beatsin16(..) value by passing it a timebase of GET_MILLIS() and a phase shift of 49151
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//I have a test matrix setup with 5 x rows of 10 ws2811 LED's all wired left to right. | |
//I needed a way to zero beatsin16 for sinelon type effects and found through testing that a phase shift of 49151 does the job. | |
#include "FastLED.h" | |
#define NUM_LEDS 50 | |
#define POWER 50 //power I want to limit my leds to. | |
// Data pin that led data will be written out over | |
#define DATA_PIN 14 | |
CRGB leds[NUM_LEDS]; | |
void setup() { | |
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS); | |
FastLED.setMaxPowerInMilliWatts(POWER); | |
Serial.begin(115200); | |
Serial.println("This nano has a burnt out gpio pin D11"); | |
} | |
uint32_t timebase=0; | |
uint32_t printTimeInterval=20; //time between serial plotter prints.) | |
uint32_t printTime=printTimeInterval; | |
uint32_t phase=49151; //phase shift required to bring back to position zero when compined with timebase of GET_MILLIS(). Found by trial and error. I don't knwo what I'm doing. | |
void loop() { | |
fadeToBlackBy( leds, NUM_LEDS, 255); | |
EVERY_N_SECONDS(10) | |
{ | |
timebase=GET_MILLIS(); //every 5 seconds I'm resetting timebase so that all five rows of leds will start at 0 position | |
} | |
uint16_t pos = beatsin16(25,0,65535,0,0); | |
uint16_t posWithTimebase= beatsin16(28,0,65535,timebase,phase); | |
uint16_t row1Pos = beatsin16(10,0,9,timebase,phase); | |
uint16_t row2Pos = beatsin16(15,0,9,timebase,phase)+10; //offset for each row position (10 leds per row) | |
uint16_t row3Pos = beatsin16(20,0,9,timebase,phase)+20; | |
uint16_t row4Pos = beatsin16(25,0,9,timebase,phase)+30; | |
uint16_t row5Pos = beatsin16(30,0,9,timebase,phase)+40; | |
leds[row1Pos]=CRGB::Blue; | |
leds[row2Pos]=CRGB::Red; | |
leds[row3Pos]=CRGB::Green; | |
leds[row4Pos]=CRGB::Yellow; | |
leds[row5Pos]=CRGB::Purple; | |
if(millis()>printTime) | |
{ | |
printTime=millis()+printTimeInterval; | |
Serial.print(row1Pos); | |
Serial.print(", "); | |
Serial.print(row2Pos); | |
Serial.print(", "); | |
Serial.print(row3Pos); | |
Serial.print(", "); | |
Serial.print(row4Pos); | |
Serial.print(", "); | |
Serial.println(row5Pos); | |
} | |
FastLED.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment