How to make this for loop both dim and brighten the LED?

704 Views Asked by At

I have a for loop made by my teacher that dims (or brightens) an LED connected to a PIC18F2455. I have to make the code do both, first brighten, then dim it, but my C skills aren't good enough for this. How can I make this happen?

int count=500;
while(1){
    for (int i=0; i<count;i++){
        LED = 0;
        for(int j=0;j<i;j++);
            LED = 1;
        for (int j=0;j<count-i;j++);
    }
}
1

There are 1 best solutions below

0
On

You can use PWM to set the brightness or You can set the dim and brighten with this way. The second way is you can use this with software like that.

You can play with the ms variable and you can set the brightness.

#define MAX_DELAY 1000;
int ms=0;

while(1) {
LED=0;
delayMs(ms);
LED1(1)
delayMs(MAX_DELAY-ms);  
}