Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

reed switch and uses

Status
Not open for further replies.

gatoulisss

New Member
hello guys, i want to use a reed switch like an on/off switch but also as selector.
i have connected it in a pull up resistor and to a pic16f88 port. the use i want to make for example is 3sec the magnet to the switch then system on if i release and put the magnet again for 3 sec there then it is becoming off, but if i dont release then after 4 sec (3-on+1) then is selecting mode A, 5 sec (3-on+2) then is selecting mode B and 6 sec (3-on+3) then is selecting mode C till i release. in the system program im checking a sensor and is in 4 mode silent (on state) 15sec ring (mode A) 30sec ring (mode B) and last 60 sec ring (mode C)
i have problem in ho to use the on-off and the mode selector code... any help with it?
 
Read up on "contact debouncing". It can be done in hardware or software. A mechanical switch makes contact many times (bounces) before settling.
 
i was thinking something like this for on off:
for (;; ){
start:
if (porta.f1==0){
on=1;
delay_ms(3000);
if (porta.f1==0 && on==1) {
......
.....}
if (porta.f1==0) {
on=0;
delay_ms(3000);
if (porta.f1==0 && on==0) {
goto start;
}
}
}
 
Check out contact debouncing. Also look at the reading of the switch at intervals using interrupts and count the number of intervals.
10-50 mS might be an OK time for a bounce.

Nothing is going to happen when waiting for the delay to be up.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top