could use some help with buttons, cycles and starting/stopping
LBwaterCo
Posts: 6
Hello,
I've been a lurker here for a week or so now, good info here.
I recently got assigned a project at work and the boss handed me a BS2.
I haven't had much experience with the Basic Stamp , but I think I got the hardware part figured out, and some coding (for testing my buttons)
So,
what I am trying to do is set up a timer / cycle changer for our water tanks.
I have been reading and I think I may need a clock chip to get my timings correct, but for now I suppose pauses would work.
I have been checking the forums and manuals but without much success.
Seems I start adding code and things just stop or I find another command that may do something my convoluted coding was trying to accomplish.
I am not a programmer, I'm a PC tech. Gimme a screwdriver and I can turn it like no other.
What I would like the program to do is, (start/stop/select cycles and ring a bell when finished)
I have 2 buttons and the parallax LCD to work with.
From startup:
press start button (IN0) run cycle 1 (runs a timer) or select a cycle with IN1(advance +1)
when timer is complete It will hit a relay for a bell (for now I'm using the LED from the kit on IN15)
to shut off the LED press the start/stop button (IN0)
then to advance the cycle +1 press (IN1) (there will be 7 cycles)
start current cycle use Start/stop button (IN0)
and repeat for all 7 cycles
Not sure if this outline of operations would be the way to go, so any suggestions would be appreciated.
I will continue to read the manuals and hopefully find something.
Here is what I have for my buttons
' {$STAMP BS2}
' {$PBASIC 2.5}
PRESS VAR Bit
STATE VAR Bit
SEROUT 3, 84, [12]
PAUSE 500
SEROUT 3, 84, 18, [ "Regen Timer" , CR, "SELECT A CYCLE" ]
DO
IF IN0 > 0 THEN STATE = 1 ELSE STATE = 0
IF STATE = 1 THEN HIGH 15
IF STATE = 0 THEN LOW 15
IF IN1 > 0 THEN PRESS = 1 ELSE PRESS = 0
IF PRESS = 1 THEN HIGH 14
IF PRESS = 0 THEN LOW 14
LOOP
Thank you for any help.
I've been a lurker here for a week or so now, good info here.
I recently got assigned a project at work and the boss handed me a BS2.
I haven't had much experience with the Basic Stamp , but I think I got the hardware part figured out, and some coding (for testing my buttons)
So,
what I am trying to do is set up a timer / cycle changer for our water tanks.
I have been reading and I think I may need a clock chip to get my timings correct, but for now I suppose pauses would work.
I have been checking the forums and manuals but without much success.
Seems I start adding code and things just stop or I find another command that may do something my convoluted coding was trying to accomplish.
I am not a programmer, I'm a PC tech. Gimme a screwdriver and I can turn it like no other.
What I would like the program to do is, (start/stop/select cycles and ring a bell when finished)
I have 2 buttons and the parallax LCD to work with.
From startup:
press start button (IN0) run cycle 1 (runs a timer) or select a cycle with IN1(advance +1)
when timer is complete It will hit a relay for a bell (for now I'm using the LED from the kit on IN15)
to shut off the LED press the start/stop button (IN0)
then to advance the cycle +1 press (IN1) (there will be 7 cycles)
start current cycle use Start/stop button (IN0)
and repeat for all 7 cycles
Not sure if this outline of operations would be the way to go, so any suggestions would be appreciated.
I will continue to read the manuals and hopefully find something.
Here is what I have for my buttons
' {$STAMP BS2}
' {$PBASIC 2.5}
PRESS VAR Bit
STATE VAR Bit
SEROUT 3, 84, [12]
PAUSE 500
SEROUT 3, 84, 18, [ "Regen Timer" , CR, "SELECT A CYCLE" ]
DO
IF IN0 > 0 THEN STATE = 1 ELSE STATE = 0
IF STATE = 1 THEN HIGH 15
IF STATE = 0 THEN LOW 15
IF IN1 > 0 THEN PRESS = 1 ELSE PRESS = 0
IF PRESS = 1 THEN HIGH 14
IF PRESS = 0 THEN LOW 14
LOOP
Thank you for any help.
Comments
I do have one relay already NTE R22-1D16-5/6 to control a bell we have.
That board does look nice but the 4 channels may not be needed.
Thanks for the fast reply.
I wasn't sure about the button command, I was having troubles earlier with the 'bounces'. Thought I had it taken care of, but Button should work better.
Now I'm trying to wrap my head around your coding. I try to load it, but it says it is missing some labels
turningOn
turningOff
changedPhase
I tried to make a new subroutine for the missing labels witout success. They end up stopping the program or "overloading"? the BS2 (on board LED goes out)
Hate to have you guys do my work for me, I'm just stuck on this.
Thanks again for looking.
The labels are flagged as undefined because they are. You have to supply subroutines with those labels and, like all subroutines, they have to return to the point of call using a RETURN statement. turningON gets called when the on/off button is first pushed. turningOff gets called when the on/off button is first released. changedPhase gets called each time the other button is pushed and the newPhase variable will be incremented each time with a roll-over after 7. The first time changedPhase is called, newPhase will be 1. The second time, it will be 2. The 7th time, it will be 7. The 8th time, it will be 0 then it will repeat the cycle. I'm assuming that zero is a "do nothing" phase and 1-7 are active phases that do something.
I was hoping to have all my ducks in a row when asking about this. I've seen your previous posts
Anyways, I made some progress with the sample you gave me. I added the missing subroutines and was able to get the majority of the project working.
There are a couple problems, but with some fiddling ( and some help from our guys here) , I should be able to figure it out.
One thing I think I need more help on are adding the delays or pauses during the 7 cycles. What I'm trying to do is after I select a cycle with Button 1 "newPhase" I would like it to link to a timer after I click Button0.
So basically the 7 cycles would all have differently timed pauses, all started and stopped from Button 0.
What I am not finding is a way to select these variables, (need to study more) and a way to display them on a LCD
Hope Im not being too much of a pain. I promise I will read more 'Basic Stamp Syntax and Reference Manual' after work. haha
Thank You for all your help
I was distracted by my PC duties last week and didn't have much time to work on this.
I did some studying over the weekend and hopefully I can piece this together.
it has 2 buttons, a warning bell, 8 timed cycles and a nice LCD readout.
timing is a little off, maybe 4 seconds slow for 10 minutes , but that's acceptable since there isn't a timing chip.
Not sure if you want a copy of the program to look at or whatever (let me know)
But thanks again for the help (and reading suggestions)