Maker Pro
Maker Pro

How to make the brightness of the LED change?

bancroft

Apr 23, 2021
81
Joined
Apr 23, 2021
Messages
81
I have done a preliminary effect of the project, now it is still missing to control the LED brightness change by clicking the number + or number - of the touch screen. When I click on "+" I want the LED brightness to get brighter and brighter as the number increases and conversely decreases. Is this possible to achieve? If so is there a sample code?
By the way, I use Arduino UNO and F5LED.
 

Martaine2005

May 12, 2015
4,932
Joined
May 12, 2015
Messages
4,932
I don't know anything about code for arduino but I do have lots of libraries that have sample and complete codes.
The code you want would be for PWM (pulse width modulation).
I think 'FastLED' has all you want. Check it out in your Arduino library.

Martin
 

bancroft

Apr 23, 2021
81
Joined
Apr 23, 2021
Messages
81
I don't know anything about code for arduino but I do have lots of libraries that have sample and complete codes.
The code you want would be for PWM (pulse width modulation).
I think 'FastLED' has all you want. Check it out in your Arduino library.

Martin
Thank you very much for the suggestion, I installed this library in my Arduino IDE, do you have some sample code? Or which example from this library should I choose to learn?
 

Martaine2005

May 12, 2015
4,932
Joined
May 12, 2015
Messages
4,932
I'll leave this open for the experienced members to answer.
But I will say that some of the code names in the libraries are rather strange and don't always describe it's function.
Adafruit libraries also have lots of examples.
I would suggest broadboarding or connecting your LEDs and try different examples.

Martin
 

bancroft

Apr 23, 2021
81
Joined
Apr 23, 2021
Messages
81
I'll leave this open for the experienced members to answer.
But I will say that some of the code names in the libraries are rather strange and don't always describe it's function.
Adafruit libraries also have lots of examples.
I would suggest broadboarding or connecting your LEDs and try different examples.

Martin
Yes I will, thank you very much!
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
The FASTLED library is for adressable RGB LEDs, not suitable for controlling the brightness of a standard LED via PWM.
Here is a simple example for controlling the brightness of an LED using PWM (in the disguise of AnalogWrite()) without any additional library.
Replace the potentiometer and the associated code by your code that evaluates the '+' and '-' softbuttons on your touchscreen.
 

bancroft

Apr 23, 2021
81
Joined
Apr 23, 2021
Messages
81
The FASTLED library is for adressable RGB LEDs, not suitable for controlling the brightness of a standard LED via PWM.
Here is a simple example for controlling the brightness of an LED using PWM (in the disguise of AnalogWrite()) without any additional library.
Replace the potentiometer and the associated code by your code that evaluates the '+' and '-' softbuttons on your touchscreen.
Thank you very much, that's a very detailed tutorial! I'll try to modify this code and understand what it means, thank you again!
 

mydasmith

Sep 21, 2022
1
Joined
Sep 21, 2022
Messages
1
A LED is a mini light bulb. A tiny component that generates light.

There are two methods for adjusting the brightness of the LED:

1. Modify the value of the resistor

Simply connect a potentiometer in series with the LED to change the brightness by adjusting the resistor value. The brightness of the LED will change as you turn the resistor's knob.

2. Quickly switch it on and off.

Another technique is to quickly turn the LED on and off. Possibly hundreds of times per second. A microcontroller is typically the best choice for this. The amount of time an LED is on as opposed to off can be changed to give the appearance of changing brightness to the eye.
 
Last edited by a moderator:
Top