Please help new guy with some simple code?
Hard Times
Posts: 7
Thanks in advance to all that try to get me going down the correct path. I have been trying for weeks to get a simple piece of code working right, and it's all to no avail. I have had no training on how to program, but I can mostly slug it out by the seat of my pants. Until now!··I won't bother to show you guys·the code I've come up with·that·won't work. Frustration is very frustrating! The BS2 control I'm after is very easy to describe:
·1.There is one single pole Switch that will be the only external input. Call it IN1.·(Off·= LOW and On =HIGH)
·2. There are only two outputs that need to change from LOW to HIGH and back. Call them Pin 2 and Pin 3. (LOW condition shall be the default.)
·3. When IN1 is LOW, Pin 2 and Pin 3 shall be LOW and stay there until IN1 goes HIGH (Switch to ON)
·4. When IN1 goes HIGH, Pin 2 shall go HIGH and Pin 3 shall stay LOW.
·5. (Now here comes the difficult part for me) A "timing" piece of code needs to monitor IN1. If IN1 goes·LOW again before 10 consecutive·seconds has elapsed, then revert to (3. above), reset the timer to zero, and wait until·(4. above)·to happen. Do this for·each IN1=High condition
·6.· Now, satisify the "if happened·"condition of·IN1·= HIGH for at least 10 consecutive·seconds·before it·went LOW
·7. For the next and all subsequent IN1= HIGH conditions (because 10 consecutive·seconds did elapse)· Pin 3 will go·HIGH and Pin 2 shall stay LOW
·8. Because 10 consecutive·seconds has and did occur for Pin 2·, Pin 3 = HIGH·shall be the only responce to IN1 = HIGH until power down of the whole circuit.
·I hope this explaination of my conditions make sense.·If not, then let's try this.· I need to have S1 control
·LED 1 each time S1 is thrown. If, however, LED 1 is ever on 10 consecutive seconds or longer, then S1·will only control LED 2. LED 1 will stay off until the end of time (or at least a reset/power down occurs)·because it lit once for those 10 consecutive seconds.
That sounds better perhaps. I know most of you guys think this is a very simple piece of code to get right.· One day I·might think so too! I'm wondering if the POLLIN command·will be the secret answer?
Thank You,
Hard Times (Old man learning new Tricks)
·
·1.There is one single pole Switch that will be the only external input. Call it IN1.·(Off·= LOW and On =HIGH)
·2. There are only two outputs that need to change from LOW to HIGH and back. Call them Pin 2 and Pin 3. (LOW condition shall be the default.)
·3. When IN1 is LOW, Pin 2 and Pin 3 shall be LOW and stay there until IN1 goes HIGH (Switch to ON)
·4. When IN1 goes HIGH, Pin 2 shall go HIGH and Pin 3 shall stay LOW.
·5. (Now here comes the difficult part for me) A "timing" piece of code needs to monitor IN1. If IN1 goes·LOW again before 10 consecutive·seconds has elapsed, then revert to (3. above), reset the timer to zero, and wait until·(4. above)·to happen. Do this for·each IN1=High condition
·6.· Now, satisify the "if happened·"condition of·IN1·= HIGH for at least 10 consecutive·seconds·before it·went LOW
·7. For the next and all subsequent IN1= HIGH conditions (because 10 consecutive·seconds did elapse)· Pin 3 will go·HIGH and Pin 2 shall stay LOW
·8. Because 10 consecutive·seconds has and did occur for Pin 2·, Pin 3 = HIGH·shall be the only responce to IN1 = HIGH until power down of the whole circuit.
·I hope this explaination of my conditions make sense.·If not, then let's try this.· I need to have S1 control
·LED 1 each time S1 is thrown. If, however, LED 1 is ever on 10 consecutive seconds or longer, then S1·will only control LED 2. LED 1 will stay off until the end of time (or at least a reset/power down occurs)·because it lit once for those 10 consecutive seconds.
That sounds better perhaps. I know most of you guys think this is a very simple piece of code to get right.· One day I·might think so too! I'm wondering if the POLLIN command·will be the secret answer?
Thank You,
Hard Times (Old man learning new Tricks)
·
Comments
You can use a PAUSE 10000 command, but meanwhile you will not be able to have the Stamp do something else.
If you change the description of behaviour for the program a bit you should be able to meet both the desirable and the feasible .
You have to deal with single tasked microcontroller, the single tasking is limiting in this case.
Regards,
Klaus
Thanks.
for i = 0 to 40
pause 250
if pin 1 = 1 then something
next i
-1
"If IN1 goes LOW again before 10 consecutive seconds has elapsed, then revert to (3. above), reset the timer to zero, and wait until (4. above) to happen. Do this for each IN1=High condition"
To the following:
-2
" IF IN1=LOW at the end of the 10 second period then......"
The meaning is the same but phrase 2 is much more easy to implement in PBasic.
Regards,
Klaus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
This is exactly what I was looking for.· You are ·DA MAN!!··I can tell you I was not even close with the stuff I was coming up with.· I don't think I would have ever come close to your simple and elegant code! This works as exactly as advertised.·
Many, many honest and sincere Thank You's.
Hard Times (Old Man who has learned a new Trick today!)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
With an ADC0831, I can read the voltage from 0 to 5 volts, but I want
to read the battery voltage of my· snowmobile by using a resistor as a
voltage divisor to read at least up to 20 volts, so I want to get the decimal
number ( 0 to 255 ) to separate the 20 volts and then putting some math ratio
to to display the voltage onto a serial LCD i.e. 255 / 20 = 12 units per volts,
but it does not work·so, how ca I do it,?
Thank you
With an ADC0831, I can read the voltage from 0 to 5 volts, but I want
to read the battery voltage of my snowmobile by using a resistor as a
voltage divisor to read at least up to 20 volts, so I want to get the decimal
number ( 0 to 255 ) to separate the 20 volts and then putting some math ratio
to to display the voltage onto a serial LCD i.e. 255 / 20 = 12 units per volts,
but it does not work so, how ca I do it,?
samsam
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
DTQ
·· Yes, two resistors are required, and it might be slightly easier on the math to adjust the range for 10 steps per volts, or .1 volts/step.· And by the way, you should start a new thread when posting your new questions.· Adding them to the end of someone else's unrelated thread might cause them to go un-noticed by many.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com