357__LEDS FADDING FOR ARDUINO MEGA
Quote from Defran on March 4, 2024, 2:26 pm357_LEDS FADDING FOR ARDUINO MEGA (Simulide R2220 or Higher)
This example uses the 15 PWM outputs of the Arduino Mega to perform a progressive dimming and sliding effect on 15 LEDs in a repetitive motion. The travel speed can be adjusted using a potentiometer.
SCHEME:
The example is based on an Arduino Mega with 15 LEDS connected (cathode to ground) to its PWM outputs: D2 to D13 plus D44 to D46. An adjustable voltage device from 0 to 5V is connected to A0 to regulate the travel speed. Here we use a subcircuit that, through an internal sliding potentiometer, achieves the aforementioned voltage.
To learn more about Arduino Mega: https://repositorio.uisek.edu.ec/bitstream/123456789/2893/7/ArduinoMega2560Datasheet.pdfPROGRAM:Arduino C program to compile as Mega in the Arduino IDE or in Simulide: Compiler/Board Configuration, Mega.
// LEDS FADDIG MEGA BY PWM. DEFRAN24. // COMLILE AS MEGA IN SIMULIDE COMPILER SETTING. int brigh[] ={0,20,40,60,80,100,120,140,160,180,200,220,215,230,250}; // brightness for the LEDS. int led[] ={2,3,4,5,6,7,8,9,10,11,12,13,44,45,46}; // MEGA PWM pins int Fadenum[]={5,5,5,5,5,5,5,5,5,5,5,5,5,5,5}; // Number of points to fade. int reta=2; void setup() { for(int i=0; i<16; i++) pinMode(led[i], OUTPUT); // Pins to OUTPUT. digitalWrite(0,HIGH); digitalWrite(1,HIGH); } void loop() { for(int i=0; i<15; i++) { reta=analogRead(A0)/225; // Manual speed. analogWrite(led[i], brigh[i]); // Set the brigh of 15 pins brigh[i] += Fadenum[i]; // Change the brigh for next time. if (brigh[i]==0 || brigh[i]==255) { Fadenum[i]=-Fadenum[i]; // Reverse the direction. } delay(reta); } }
SUBCIRCUITS:This example integrates several subcircuits located in the "data" folder into the ZIP attached. This folder must always be next to the "sim1" scheme so that it can be executed. A subcircuit is a “custom” circuit that accumulates a set of Simulide base components (primitive function) to obtain a new or an adapted function. These subcircuits are treated by Simulide as another component of its own structure. User can create his own subcircuits or use the ones published here in your own designs once the procedure is known, explained in detail in the Simulide tutorials: https://simulide.com/p/subcircuits/* Communication with the author: Simulide/User/Messages/DefranP. de Francisco.
357_LEDS FADDING FOR ARDUINO MEGA (Simulide R2220 or Higher)
This example uses the 15 PWM outputs of the Arduino Mega to perform a progressive dimming and sliding effect on 15 LEDs in a repetitive motion. The travel speed can be adjusted using a potentiometer.
SCHEME:
The example is based on an Arduino Mega with 15 LEDS connected (cathode to ground) to its PWM outputs: D2 to D13 plus D44 to D46. An adjustable voltage device from 0 to 5V is connected to A0 to regulate the travel speed. Here we use a subcircuit that, through an internal sliding potentiometer, achieves the aforementioned voltage.
Arduino C program to compile as Mega in the Arduino IDE or in Simulide: Compiler/Board Configuration, Mega.
// LEDS FADDIG MEGA BY PWM. DEFRAN24.
// COMLILE AS MEGA IN SIMULIDE COMPILER SETTING.
int brigh[] ={0,20,40,60,80,100,120,140,160,180,200,220,215,230,250}; // brightness for the LEDS.
int led[] ={2,3,4,5,6,7,8,9,10,11,12,13,44,45,46}; // MEGA PWM pins
int Fadenum[]={5,5,5,5,5,5,5,5,5,5,5,5,5,5,5}; // Number of points to fade.
int reta=2;
void setup()
{
for(int i=0; i<16; i++) pinMode(led[i], OUTPUT); // Pins to OUTPUT.
digitalWrite(0,HIGH);
digitalWrite(1,HIGH);
}
void loop()
{
for(int i=0; i<15; i++)
{
reta=analogRead(A0)/225; // Manual speed.
analogWrite(led[i], brigh[i]); // Set the brigh of 15 pins
brigh[i] += Fadenum[i]; // Change the brigh for next time.
if (brigh[i]==0 || brigh[i]==255)
{
Fadenum[i]=-Fadenum[i]; // Reverse the direction.
}
delay(reta);
}
}