Hello. I am using the fastled library to light up an led strip and I'm using the attiny85 to process the animations. I need to lose about 1100 bytes of data so it will flash. I tried using port commands, but I'm terrible at that- translating from a data sheet to the developerboard layout and the gpios to the PB#... its rough. I took out a couple animations I didn't care for but I'm still above the size limit.
I heard you can edit the library, but that is a new concept to me as well. What are my options to size down the code and pleeeeease don't refer me to instructables, because that was not helpful.
here is my sketchy:
//Kent's Steampunk LED Goggles v2.42p
//Adapted from "100 lines of code example" "I ripped all
//the programs out and made them button selectable. And
//you can set brightness with a button too I guess.
//connect the pushbutton between ground and pin. use internal pullup resistor.
#include "FastLED.h"
FASTLED_USING_NAMESPACE
#define DATA_PIN 4
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 42
CRGB leds[NUM_LEDS];
byte BRIGHTNESS = 20;
#define FRAMES_PER_SECOND 120
uint8_t gHue = 0; // rotating "base color"
byte selectorPin = 3; //5 and 2 write LOW
byte brightnessPin = 0 ;
byte bright = 50;//brightness level counter
byte selector = 0; // counter for the number of button presses
bool oldState = HIGH;
bool oldStateb = HIGH;
byte i = 0;
byte j = 0;
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
pinMode(selectorPin, INPUT_PULLUP);
pinMode(brightnessPin, INPUT_PULLUP);
DDRB |= (1 << PB2); //pin 2 output attiny85
DDRB |= (1 << PB5); //this is where I tried to do the port commands, but they didn't save enough memory.
}
void loop() {
//******************************************************brightness
PORTB &= ~(1 << PB2);//ground for brightness pin
PORTB &= ~(1 << PB5);//ground for selector pin
FastLED.setBrightness(BRIGHTNESS);
bool newStateb = digitalRead(brightnessPin);
// Check if state changed from high to low (button press).
if (newStateb == LOW && oldStateb == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newStateb = digitalRead(brightnessPin);
if (newStateb == LOW) {
bright++;
if (bright > 3)
bright=0;}
}
oldStateb = newStateb;
if (bright == 0) {BRIGHTNESS = 5;}
if (bright == 1) {BRIGHTNESS = 20;}
if (bright == 2) {BRIGHTNESS = 50;}
if (bright == 3) {BRIGHTNESS = 100;}
//********************************************************selector
bool newState = digitalRead(selectorPin);
if (newState == LOW && oldState == HIGH) {
delay(20);
newState = digitalRead(selectorPin);
if (newState == LOW) {
selector++;
if (selector > 7)
selector=0;}
}
oldState = newState;
if (selector == 0) {_3DGoggles();}
if (selector == 1) {rainbow(); }
if (selector == 2) {rainbowWithGlitter();}
if (selector == 3) {confetti();}
if (selector == 4) {sinelon();}
if (selector == 5) {bpm();}
if (selector == 6) {juggle();}
if (selector == 7) {theaterChaseRed();}
}
void rainbow() {
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
fill_rainbow(leds, NUM_LEDS, gHue, 7);
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
}
//*******************************************************
void rainbowWithGlitter() {
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
fill_rainbow(leds, NUM_LEDS, gHue, 7);
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
//glitter
if ( random8() < 80) {
leds[ random16(NUM_LEDS) ] += CRGB::White;}
}
//*******************************************************
void confetti(){
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
fadeToBlackBy( leds, NUM_LEDS, 10);
byte pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
}
//******************************************************
void sinelon(){
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
fadeToBlackBy( leds, NUM_LEDS, 20);
byte pos = beatsin16( 13, 0, NUM_LEDS-1 );
leds[pos] += CHSV( gHue, 255, 192);
}
//**********************************************************
void bpm(){
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
byte BeatsPerMinute = 80;
CRGBPalette16 palette = PartyColors_p;
byte beat = beatsin8( BeatsPerMinute, 64, 255);
for( byte i = 0; i < NUM_LEDS; i++) { //9948
leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));}
}
//************************************************************
void juggle() {
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
for( int i = 0; i < 8; i++) {
leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
dothue += 32;}
}
//**********************************************************
void _3DGoggles() {
for( byte i = 0; i < NUM_LEDS/2; i++) {
leds[i] = CRGB:: Red;}
for( byte i = NUM_LEDS/2; i < NUM_LEDS; i++) {
leds[i] = CRGB:: Blue;}
FastLED.show();
}
void theaterChaseRed() {
if (j > 3) {
j = 0;
}
for (byte i = 0; i < NUM_LEDS; i = i + 3) {
leds[i+j] = CRGB::Red; //turn every third pixel on
}
FastLED.show();
FastLED.delay(5000 / FRAMES_PER_SECOND);
for (byte i = 0; i < NUM_LEDS; i = i + 3) { //turn off pixels
leds[i+j] = CRGB::Black;
}
j = j + 1;
}
Thank you for your help!