1 Reply Latest reply on Jul 27, 2017 3:13 AM by user_1377889

    Unable to use one shot timer a second time for LED

    injunear_2560726

      I am trying to have the LED stay on for 5 seconds after I push the button on the cy8ckit-049-42xx prototyping kit.Currently, it works the first time I push the button but the next time the LED stays on forever. I am using Win 7 and PSoC Creator 4.1.

         

      Here is the relevant code.

         

      int main(void)
      {
          CyGlobalIntEnable; /* Enable global interrupts. */

         

          /* Place your initialization/startup code here (e.g. MyInst_Start()) */
          My_Timer_Enable();
          int Flag = 0;
          //LED_Write(1);
          for(;;)
          {
              LED_Write(0);
              if(!SW2_Read() && !Flag)
              {
                  My_Timer_Start();
                  Flag = 1;
              }
              
              while((My_Timer_ReadCounter()>0)&&Flag)
              {
                  LED_Write(1);
                  CyDelay(100);
              }
              
              if(My_Timer_ReadCounter()<1)
              {
                  Flag=0;
                 // My_Timer_Init(); // Makes no difference
              }
          }
      }

         

       

         

      I have attached the code bundle.

         

      Thank you for your kind help.