I'm trying to fade a LED, without using PWM? only using software? anyone know how to do it?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi

I tried with CY8CKIT-059.

main.c

=====================

#include "project.h"

#define DELTA_VALUE 5

int main(void)

{

    int period = 1000 ;

    int count = 0 ;

    int comp = 0 ;

    int delta = DELTA_VALUE ;

 

    CyGlobalIntEnable; /* Enable global interrupts. */

    for(;;)

    {

        if (count < comp) {

            LED_Write(0) ;

        } else {

            LED_Write(1) ;

        }

        count++ ;

        if (count >= period) {

            count = 0 ;

            comp += delta ;

            if (comp >= period) {

                delta = -DELTA_VALUE ;

            } else if (comp <= 0) {

                delta = DELTA_VALUE ;

            }

        }

        CyDelayUs(1) ;

    }

}

=====================

moto

View solution in original post

0 Likes
1 Reply
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi

I tried with CY8CKIT-059.

main.c

=====================

#include "project.h"

#define DELTA_VALUE 5

int main(void)

{

    int period = 1000 ;

    int count = 0 ;

    int comp = 0 ;

    int delta = DELTA_VALUE ;

 

    CyGlobalIntEnable; /* Enable global interrupts. */

    for(;;)

    {

        if (count < comp) {

            LED_Write(0) ;

        } else {

            LED_Write(1) ;

        }

        count++ ;

        if (count >= period) {

            count = 0 ;

            comp += delta ;

            if (comp >= period) {

                delta = -DELTA_VALUE ;

            } else if (comp <= 0) {

                delta = DELTA_VALUE ;

            }

        }

        CyDelayUs(1) ;

    }

}

=====================

moto

0 Likes