1 Reply Latest reply on Oct 12, 2019 7:07 PM by MoTa_728816

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

    KiTh_4442166

      breathing LED using software only.

        • 1. Re: I'm trying to fade a LED, without using PWM? only using software? anyone know how to do it?
          MoTa_728816

          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