Hi everyone,
Can't for the life of me figure out this simple problem.
I haven't included all my code as it is just a small problem.
Basically I'm using FastLED library and I have set the brightness as:
#define BRIGHTNESS 5 (I wanted it really low for most part)
FastLED.setBrightness(BRIGHTNESS );
Later on I have a made a small function which I use a button press to conrol leds but I want the brightness to change to max 255.
But I'm not sure how to do this....Or where to look......
Thanks
1 Like
The setBrightness applies a scaleing factor to all subsequent values, so to get a full brightness you have to call that function again with a new value before you set the colour. LEDs set under the old value of brightness will stay the same until they are changed under the new brightness setting.
Thank you for your answer. I would appreciate it if you could you give me something more practical so I can make it work in my code.
Basically I would like protonSetup(); function to run at max brightness but at other times back to regular BRIGHTNESS
Here is my partial code:
#include <FastLED.h>
///////////////////////////
#define LED_SHOOT 6
#define COLOR_ORDER GRB
#define CHIPSET WS2812
#define NUM_LEDS3 6
#define BRIGHTNESS 5
#define FRAMES_PER_SECOND 60
int buttonPin = A0;
int buttonFire = 2;
int buttonStopEngine = A2;
int buttonSong = A4;
CRGB leds3[NUM_LEDS3];
////////////////////////////////
#define NUM_LEDS 4
#define NUM_LEDS2 4
#define DATA_PIN 9
#define DATA_PIN2 7
CRGB leds [NUM_LEDS];
CRGB leds2 [NUM_LEDS2];
int delayTime = 200;
int delayTimes = 400;
int longDelayTime = 1000;
void setup() {
Serial.begin(9600);
delay(3000);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2);
//////////////////////////////////////////////////
delay(3000); // sanity delay
FastLED.addLeds<CHIPSET, LED_SHOOT, COLOR_ORDER>(leds3, NUM_LEDS3).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS );
//////
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
circleLoop();
if (digitalRead(buttonPin) == LOW) {
Serial.println("Button press available");
delay (500);
if (digitalRead(besyPin) == HIGH) { //if no mp3 playing
Serial.println("Play Mp3");
myDFPlayer.playMp3Folder(1);
delay(200);
while (digitalRead(besyPin) == LOW) {
protonSetup();
}
}
}
////////////////////////////////////////////////////////
if (digitalRead(buttonFire) == LOW) {
Serial.println("Button press available");
delay (500);
if (digitalRead(besyPin) == HIGH) { //if no mp3 playing
Serial.println("Play Mp3");
myDFPlayer.playMp3Folder(2);
//myDFPlayer.play(1);//should be 1 if only 1 track on SD card.
delay(200);
while (digitalRead(besyPin) == LOW) {
protonShoot();
}
}
}
////////////////////////////////////////////////////////
if (digitalRead(buttonStopEngine) == LOW) {
Serial.println("Button press available");
delay (500);
if (digitalRead(besyPin) == HIGH) { //if no mp3 playing
Serial.println("Pause Mp3");
myDFPlayer.playMp3Folder(3);
delay(1000);
while (digitalRead(besyPin) == LOW) {
protonGunShutDown();
}
}
}
////////////////////////////////////////////////////////
if (digitalRead(buttonSong) == LOW) {
Serial.println("Button press available");
delay (500);
if (digitalRead(besyPin) == HIGH) { //if no mp3 playing
Serial.println("Play Mp3");
myDFPlayer.playMp3Folder(4);
delay(200);
while (digitalRead(besyPin) == LOW) {
circleLoop();
}
}
}
////////////////////////////////////////////////////////
myDFPlayer.stop();
////////////////////////////////////////////////////////
}//close loop
////////////////MY-FUNCTIONS////////////////////////////////
void protonSetup() {
leds[0] = CRGB::White;
leds2[0] = CRGB::Red;
leds3[0] = CRGB::White;
leds3[1] = CRGB::White;
leds3[2] = CRGB::White;
leds3[3] = CRGB::White;
leds3[4] = CRGB::White;
leds3[5] = CRGB::White;
FastLED.show();
delay (delayTimes);
leds[1] = CRGB::White;
leds2[1] = CRGB::Red;
leds3[0] = CRGB::White;
leds3[1] = CRGB::White;
leds3[2] = CRGB::White;
leds3[3] = CRGB::White;
leds3[4] = CRGB::White;
leds3[5] = CRGB::White;
FastLED.show();
delay (delayTimes);
leds[2] = CRGB::White;
leds2[2] = CRGB::Red;
leds3[0] = CRGB::White;
leds3[1] = CRGB::White;
leds3[2] = CRGB::White;
leds3[3] = CRGB::White;
leds3[4] = CRGB::White;
leds3[5] = CRGB::White;
FastLED.show();
delay (delayTimes);
leds[3] = CRGB::White;
leds2[3] = CRGB::Red;
leds3[0] = CRGB::White;
leds3[1] = CRGB::White;
leds3[2] = CRGB::White;
leds3[3] = CRGB::White;
leds3[4] = CRGB::White;
leds3[5] = CRGB::White;
FastLED.show();
delay (delayTimes);
leds[0] = CRGB::Red;
leds2[0] = CRGB::White;
leds3[0] = CRGB::White;
leds3[1] = CRGB::White;
leds3[2] = CRGB::White;
leds3[3] = CRGB::White;
leds3[4] = CRGB::White;
leds3[5] = CRGB::White;
FastLED.show();
delay (delayTimes);
leds[1] = CRGB::Red;
leds2[1] = CRGB::White;
leds3[0] = CRGB::White;
leds3[1] = CRGB::White;
leds3[2] = CRGB::White;
leds3[3] = CRGB::White;
leds3[4] = CRGB::White;
leds3[5] = CRGB::White;
FastLED.show();
delay (delayTimes);
leds[2] = CRGB::Red;
leds2[2] = CRGB::White;
leds3[0] = CRGB::Black;
leds3[1] = CRGB::Black;
leds3[2] = CRGB::Black;
leds3[3] = CRGB::Black;
leds3[4] = CRGB::Black;
leds3[5] = CRGB::Black;
FastLED.show();
}
would appreciate it if you could you give me something more practical so I can make it work in my code
Ask about what you do not understand in my answer. In my opinion what I told you was very practical.
I can’t see in your code where you want it brighter.
Also hint:- use arrays then the code is much much shorter.
Hi thanks. I didn't mean to be rude. Sorry if I offended.
I didn't include all my code as there was a limitation on the website but I included protonSetup(); in uploaded code.
I wanted this to be at maxBrightness for the period of when this function is running only. Then return to regular brightness after that function has finished running. I thought there must be an easy way to do this and need advice. I am unfamilar with FastLED and thought maybe there might be somewhere I may be able to include in the "argument" to adjust brightness settings for a specific function. I hope I could explain myself clearly. As I am quite new to this I need specific examples if possible or a link with the answers I search.
Thank you sincerely
I fail to see how you are asking about my previous advice, you just seem to be stating your problem again like you did in the original post. In reply #1 I told you what to do and why it worked. So you seem not to be able to understand this and not capable of saying what you don't understand. So sod the understanding part just:-
to use full brightness:-
- Set the brightness to 255 using the set brightness call.
- Set the colour you want to show at full brightness
- Set brightness back down to 5
Note you can call the show method after step 2 or step 3 and the full brightness colour will continue at full brightness until that LED is set to a new value THEN the new value will reflect the CURRENT brightness setting.
When doing something new like this then get rid of all code that does other stuff, it only gets in your way and hides a problem. No one wants to wade through lines and lines of stuff irrelevant to your problem. Once you have demonstrated to yourself that you know what you are doing then you can surround it with other stuff knowing that your new bit works.
Thank you! I think I have figured this brightness issue out now.
Sorry about the confusion, it's hard to explain myself and understand others when I don't fully know what is going on myself.
Cheers!