cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

Anonymous
Not applicable

Hi everyone !

i haven't good skills in programmation and i have a question. I work with an Opamp and i want to turn off a Red led when my voltage > 3.0V and turn off when voltage < 3.0V. I am good with that, but i also want to turn on a Green led, during 2sec,  when the voltage < 3.0V. Only one time. If the voltage become higher than 3.0V  and become one more time lower than 3.0V, i just want 2sec of GreenLed and stop.

I'm in a loop and its a problem

if (Vout_tension > 3.0)

            {

                RED_Led_Write(~RED_Led_Read());

                CyDelay(500);

                GREEN_Led_Write(0);

            }

        else

            {

                RED_Led_Write(0);

                GREEN_Led_Write(1);

                CyDelay(2000);

                GREEN_Led_Write(0)

            }

GREEN_Led is always turn on when Vout_tension < 3.0, because im in a loop. Someone can help me to switch off the led after 2sec ?

Thank you for help, and I'm very sorry about my bad english.

Yohann

0 Likes
1 Solution
RyanZhao
Moderator
Moderator

Hi Yohann,

In my opinion, you can add a global variable as a flag and initial it as 0. In the loop, green LED turned on once, set the flag as 1, if the flag not 0, not turn on green LED any more.

Kindly let me know if I misunderstood your question.

Thanks,

Ryan

View solution in original post

0 Likes
4 Replies
RyanZhao
Moderator
Moderator

Hi Yohann,

In my opinion, you can add a global variable as a flag and initial it as 0. In the loop, green LED turned on once, set the flag as 1, if the flag not 0, not turn on green LED any more.

Kindly let me know if I misunderstood your question.

Thanks,

Ryan

View solution in original post

0 Likes
Anonymous
Not applicable

if i understood what you said i need create an other void function to stop the led ?

0 Likes
RyanZhao
Moderator
Moderator

Yes. I'm afraid more code is must.

You can use a Timer component. Refer more code examples in PSoC Creator.

Thanks,

Ryan

Anonymous
Not applicable

I use a flag and my led work. Thank you for your help.

0 Likes