[SOLVED] Counter With Opto Coupler

Status
Not open for further replies.

joserio

Newbie level 4
Joined
Jan 16, 2016
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
48
Hola,
Guys.....I need your help.

Below is the code I found on the way
Code:
 do{
    if(Button(&PORTB,5,1,0))      
                                

    {
                             Delay_ms(200);    // If button is pressed, delay 0,2s and increment "number" with 1;
                             number = number +1;

Above code is working fine, that code is counting by button pressed 1 time then increase value till xValue, now I change the button and added an opto coupler, what I mean is when opto coupler have a trigger voltage then counting for 1 time and next trigger and counting.

The trigger only 1 second then off to counting, next trigger will count again.

:fight::fight::bang::bang:
jose.
 

Please clarify:

* Do you wish for the count to continue only while the button/optocoupler is sending?

* Do you need a toggle flip-flop effect (push-On, push-Off)?

* Are you looking for code to "count to N and stop"?
 

Please clarify:

* Do you wish for the count to continue only while the button/optocoupler is sending?

* Do you need a toggle flip-flop effect (push-On, push-Off)?

* Are you looking for code to "count to N and stop"?


Hola BradtheRad,
I wish for the count to continue only while the button is sending, it mean when the button on pressed/toggle it count +1 only till the button release (only have one count), and next counting will count same.

I use an opto coupler to trigger an input, so I change
Code:
if(Button(&PORTB,5,1,0))
3 digit (0 to 1).

On my first post if I use that method, always counting when the button on pressed or toggle.



Jose.
 

Hola BradtheRad,
I already solved the issue, I just added a bit oldstate=0 then next oldstate=1.

Thank you for support.

:smile:
Joserio.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…