Switch and one Led
Jimm2
Posts: 16
What I would like to know is, Is there A way to use the Propeller Chip, so that when you hit the switch (on and off) at A slow pace. It would make the Led, stay on. But when you hit the switch, hold it down it would make the led stay off. When you didn't hit the switch, the led would be off.
PUB
dira[noparse][[/noparse]6] := 1
dira[noparse][[/noparse]21] := 0
repeat
outa[noparse][[/noparse]6] := ina[noparse][[/noparse]21] ((in this line could I put something that would make it read like this)) The ina [noparse][[/noparse]21] == 10101
Switch (101010101010101010)
Led (111111111111111111111)
Switch (000000000000000000)
Led (000000000000000000000)
0 = off
1 = on
PUB
dira[noparse][[/noparse]6] := 1
dira[noparse][[/noparse]21] := 0
repeat
outa[noparse][[/noparse]6] := ina[noparse][[/noparse]21] ((in this line could I put something that would make it read like this)) The ina [noparse][[/noparse]21] == 10101
Switch (101010101010101010)
Led (111111111111111111111)
Switch (000000000000000000)
Led (000000000000000000000)
0 = off
1 = on
Comments
I think what your asking about is totally doable, to know what the end goal/purpose was might lead to a different solution, but from what you've said here is how I would approach it:
What your saying is that if the status of the switch changes in any way over a certain period of time that would trigger the LED. And that any status of the switch which would occur beyond your pre-defined time period would then leave the LED off.
So I would make a loop that detects a change in the switches state, and when I see that its changed, I would grab a copy of the cnt (The system counter), the next time my loop caught another change in the state of the switch, it would compare the new cnt value with the one I previously recorded, and if they are close enough (whatever your needs are) , that would trigger the LED.
That would cover lighting the LED, to see if it should be off, you need to compare the current cnt with each iteration of your loop to the most recent switch-state-change captured cnt value...and again depending on your timing needs, turn off the LED.
Welcome to Prop world
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·
There is an example that is very close to this in one of the learning labs. The example lights up an LED for as long as you push a button. If you haven't looked through the labs... they are the shortest path, constructed by true professionals with all kinds of feedback from the forum... a gold mine of facts and concepts that you wouldn't otherwise come across until much later.
If you want to wait a half a second... that count (cnt) interval is represented by clkfreq/2, a tenth of a second is clkfreq/10, etc. So, you set up your interval with a variable(called interval), whose value is assigned to clkfreq/something... then you subtract your cnt values and compare the result to "interval."
Here are 4 examples, they build on each other, the last one is what your looking for I think:
LED Based on Switch:
LED Based on Timing:
LED Based on Switch Timing (how fast you press the switch repeatedly):
2 LEDs Based on Switch Timing with Different Actions:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)