Skip to content

Standardize defines and file formatting #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 39 additions & 31 deletions AnalogBasicSetup.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,62 @@ uint8_t hue;

//---------------------------------------------------------------
void setup() {
delay(1500);
pinMode(REDPIN, OUTPUT); //setup pins for controlling analog RGB LED
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
colorBars(); //display R,G,B color check during startup to confirm wiring
delay(1500);
pinMode(REDPIN, OUTPUT); //setup pins for controlling analog RGB LED
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
colorBars(); //display R,G,B color check during startup to confirm wiring
}


//---------------------------------------------------------------
//Function to update the analog LED display
void showAnalogRGB( const CRGB& rgb) {
//Note: scale8 is used to adjust values based on BRIGHTNESS
void showAnalogRGB( const CRGB &rgb) {
//Note: scale8 is used to adjust values based on BRIGHTNESS

//Also note, I needed to update this to use 255 minus the rgb
//value since the LED I am using is common anode. If your
//analog RGB LED is common cathode you don't need the "255-" part.
analogWrite(REDPIN, 255-scale8(rgb.r, BRIGHTNESS) ); //for common anode
analogWrite(GREENPIN, 255-scale8(rgb.g, BRIGHTNESS) );
analogWrite(BLUEPIN, 255-scale8(rgb.b, BRIGHTNESS) );
//analogWrite(REDPIN, scale8(rgb.r, BRIGHTNESS) ); //for common cathode
//analogWrite(GREENPIN, scale8(rgb.g, BRIGHTNESS) );
//analogWrite(BLUEPIN, scale8(rgb.b, BRIGHTNESS) );
//Also note, I needed to update this to use 255 minus the rgb
//value since the LED I am using is common anode. If your
//analog RGB LED is common cathode you don't need the "255-" part.
analogWrite(REDPIN, 255 - scale8(rgb.r, BRIGHTNESS) ); //for common anode
analogWrite(GREENPIN, 255 - scale8(rgb.g, BRIGHTNESS) );
analogWrite(BLUEPIN, 255 - scale8(rgb.b, BRIGHTNESS) );
//analogWrite(REDPIN, scale8(rgb.r, BRIGHTNESS) ); //for common cathode
//analogWrite(GREENPIN, scale8(rgb.g, BRIGHTNESS) );
//analogWrite(BLUEPIN, scale8(rgb.b, BRIGHTNESS) );
}


//---------------------------------------------------------------
void loop() {
EVERY_N_MILLISECONDS(250) { //cycle through the rainbow
fill_rainbow( leds, 1, hue);
hue = hue + 5;
}
EVERY_N_MILLISECONDS(250) { //cycle through the rainbow
fill_rainbow( leds, 1, hue);
hue = hue + 5;
}

EVERY_N_MILLISECONDS(5) { //change the master brightness
static uint8_t delta = 1;
BRIGHTNESS = BRIGHTNESS - delta;
}
showAnalogRGB( leds[0]); //update the LED display
EVERY_N_MILLISECONDS(5) { //change the master brightness
static uint8_t delta = 1;
BRIGHTNESS = BRIGHTNESS - delta;
}

showAnalogRGB( leds[0]); //update the LED display

}//end_main_loop


//---------------------------------------------------------------
void colorBars() {
//This function is called once during startup to confirm the R,G,B wiring
fill_solid(leds,1,CRGB::Red); showAnalogRGB( leds[0] ); delay(1500);
fill_solid(leds,1,CRGB::Green); showAnalogRGB( leds[0] ); delay(1500);
fill_solid(leds,1,CRGB::Blue); showAnalogRGB( leds[0] ); delay(1500);
fill_solid(leds,1,CRGB::Black); showAnalogRGB( leds[0] ); delay(500);
//This function is called once during startup to confirm the R,G,B wiring
fill_solid(leds, 1, CRGB::Red);
showAnalogRGB( leds[0] );
delay(1500);
fill_solid(leds, 1, CRGB::Green);
showAnalogRGB( leds[0] );
delay(1500);
fill_solid(leds, 1, CRGB::Blue);
showAnalogRGB( leds[0] );
delay(1500);
fill_solid(leds, 1, CRGB::Black);
showAnalogRGB( leds[0] );
delay(500);
}

137 changes: 69 additions & 68 deletions Blynk_Teensy32_USB_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@


//---------------------------------------------------------------
#include "FastLED.h" //include FastLED library
#define NUM_LEDS 32 // Number of pixels in strip
#include "FastLED.h"
#define LED_TYPE APA102
#define DATA_PIN 11
#define CLK_PIN 13
#define NUM_LEDS 32
#define COLOR_ORDER BGR
#define BRIGHTNESS 128

CRGB leds[NUM_LEDS];

void solid();
Expand All @@ -51,111 +57,106 @@ uint8_t zeRGBa[3]; //output: V2, zeRGBa data (set to "merge")
boolean buttonA; //output: V3, button (set as "switch")
uint8_t pattern; //output: V4, current pattern number

BLYNK_WRITE(V1) //slider value 0-255
{
sliderBrightness = param.asInt(); // assigning incoming value from pin V1 to a variable
BLYNK_WRITE(V1) { //slider value 0-255
sliderBrightness = param.asInt(); // assigning incoming value from pin V1 to a variable
}

BLYNK_WRITE(V2) //set as "merge" in zeRGBa widget
{
zeRGBa[0] = param[0].asInt(); //red
zeRGBa[1] = param[1].asInt(); //green
zeRGBa[2] = param[2].asInt(); //blue
BLYNK_WRITE(V2) { //set as "merge" in zeRGBa widget
zeRGBa[0] = param[0].asInt(); //red
zeRGBa[1] = param[1].asInt(); //green
zeRGBa[2] = param[2].asInt(); //blue
}

BLYNK_WRITE(V3) //toggles pixel display On/Off, set as "switch"
{
buttonA = param.asInt(); //value is either 0 or 1
BLYNK_WRITE(V3) { //toggles pixel display On/Off, set as "switch"
buttonA = param.asInt(); //value is either 0 or 1
}

BLYNK_WRITE(V4) {
switch (param.asInt()) {
switch (param.asInt()) {
case 1: {
pattern = 1; //rainbow
break;
pattern = 1; //rainbow
break;
}
case 2: {
pattern = 2; //juggle
break;
pattern = 2; //juggle
break;
}
case 3: {
pattern = 3; //sinelon (color selected by zeRGBa picker)
break;
pattern = 3; //sinelon (color selected by zeRGBa picker)
break;
}
case 4: {
pattern = 0; //solid (color selected by zeRGBa picker)
break;
pattern = 0; //solid (color selected by zeRGBa picker)
break;
}
default:
pattern = 0; //run if no pattern selected
}
pattern = 0; //run if no pattern selected
}
}

//---------------------------------------------------------------
void setup()
{
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);

FastLED.addLeds<LPD8806,11,13,GRB>(leds, NUM_LEDS);
void setup() {
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);

// FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
}


//---------------------------------------------------------------
void loop()
{
Blynk.run();
void loop() {
Blynk.run();

EVERY_N_MILLISECONDS(10) {
if (buttonA == 1) { //strip is ON.
gPatterns[pattern]();
EVERY_N_MILLISECONDS(10) {
if (buttonA == 1) { //strip is ON.
gPatterns[pattern]();

} else { //strip is OFF
FastLED.clear(); //blank out all pixel data

}

FastLED.setBrightness(sliderBrightness);
FastLED.show();
} else { //strip is OFF
FastLED.clear(); //blank out all pixel data

}

}//end_EVERY_N
FastLED.setBrightness(sliderBrightness);
FastLED.show();

EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
}//end_EVERY_N

EVERY_N_MILLISECONDS( 20 ) {
gHue++; // slowly cycle the "base color" through the rainbow
}

}//end_main_loop


//---------------------------------------------------------------
// Patterns
//---------------------------------------------------------------
void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, NUM_LEDS/8);
void rainbow() {
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, NUM_LEDS / 8);
}

void juggle() {
// four colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
for( int i = 0; i < 4; i++) {
leds[beatsin16( i+5, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
dothue += 32;
}
// four colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
for( int i = 0; i < 4; i++) {
leds[beatsin16( i + 5, 0, NUM_LEDS - 1 )] |= CHSV(dothue, 200, 255);
dothue += 32;
}
}

void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 12);
int pos = beatsin16( 13, 0, NUM_LEDS-1 );
leds[pos] += CRGB(zeRGBa[0],zeRGBa[1],zeRGBa[2]);
void sinelon() {
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 12);
int pos = beatsin16( 13, 0, NUM_LEDS - 1 );
leds[pos] += CRGB(zeRGBa[0], zeRGBa[1], zeRGBa[2]);
}

void solid()
{
// fill entire strip with a solid color
fill_solid(leds, NUM_LEDS, CRGB(zeRGBa[0],zeRGBa[1],zeRGBa[2]) );
void solid() {
// fill entire strip with a solid color
fill_solid(leds, NUM_LEDS, CRGB(zeRGBa[0], zeRGBa[1], zeRGBa[2]) );
}
Loading