Seems simple

newbe

New Member
Cant figure how! I have a switch that can be on or off + or - I need a code for prefer om8 or 20m2 if pin2( =1 ) steady state always on ) high pin3 wait 2 low pin3 ( stop meaning do once like pause for any time up to 23hours ) then if state of pin 2 toggles changes steady state at any time up to 23 hours then do the line of code again once then stop for any time up to 23 hours. ( Just want it to cause a 1 second pulse on a pin then stop then cause pulse on same pin whenever input pin state changes again then stop )
 

Dippy

Moderator
Woo.
Take a deep breath and start again.

Write it out as a list rather than a big pile ;)
If it's clearer then it's less ambiguous and people can give a clear, precise answer quickly.

Show us what you have tried so far.
 

BeanieBots

Moderator
Once written as a list in the way Dippy describes, it's then almost just a question of converting the list into code. Should be simple enough.
 

newbe

New Member
if pin3 = 1 ( or) 0 then
high 2 wait 1 low 2 stop Until pin 3 changes state again then run line of code again once till state change
 

BeanieBots

Moderator
Try it in English first.
Maybe something like this.

Switch on whatever...

Main loop
has button been pressed? (if yes then go off and do whatever)
Has 23 hours elapsed? (if yes, then go off and do whatever)
Go back to main loop

Sart of code for when button is pressed
Switch OFF whatever.
.....
 

newbe

New Member
watch pin3 if = 1 then high pin2 wait 1 low pin2 stop watch for state change
watch pin3 if =0 then high pin2 wait 1 low pin2 stop
 

hippy

Ex-Staff (retired)
I think you will also have to explain the "up to 23 hours" part in more detail as well. How accurate do you need this period to be, and how is it set ?
 

newbe

New Member
now simplified

if pin3 = 1 then high 2 wait 1 low 2 endif
if pin3 =0 then high 2 wait 1 low 2 endif


I need it to re trigger when pin 3 changes state
 

1968neil

Senior Member
Might help if we understood the question ?
What exactly are you trying to do ?

the following code might give you a start ?
Assuming that i have your question straight !

The input pin, pin 6 sits and waits for a change of state.
When triggered turns on pin2 and pin4 whilst the input pin is triggered.

Once the input dissapears its waits 4.2 seconds then turns off pin 2 and 4and goes back to monitoring the input.
This is achieved by using an interupt.
You could modify the code to suit your own needs but this should help you on the way.

Best Regards

Neil

Happy New Year !

Code:
Symbol pulsePresent = b0 ' Pulse present flag

SetInt %00000010,%00000010 ' Enable interrupt on Pin6

SetFreq M8 ' Run at 8mhz (fast as possible)

Output 2 ' Pulse present output (pin5)

pulsePresent = 0 ' No pulse seen 

Do
Pause 8400 ' Pause for 4.2s 8400 = 4.2 secs at 8mhz
If pulsePresent = 0 Then ' Was pulse seen ?
Low 2 ' No - Clear pulse present output (pin5)
Low 4 ' Output OFF (pin3) 
Else
pulsePresent = 0 ' Clear pulse seen 
End If
Loop

Interrupt:
pulsePresent = 1 ' Pulse is present
High 2 ' Set pulse present output (pin5)
High 4 ' Output ON (pin3) 
SetInt %00000010,%00000010 ' Re-enable interrupt
Return
 

newbe

New Member
Thank you very much

To save on translation errors Ill try this A cheap lamp timer has all the buttons am pm easy to set .I have it joined to a fet it gives - or ground when set to time on .When timer expires it takes away ground . The video recorder needs a pulse of 1 second to boot up and record . When the timer says thats enough shut off . Takes away - ground the picaxe needs to give 1 second pulse for recorder to save video and shut off .And doe it again when timer output fet gives - ground again
 

newbe

New Member
even simpler

Wall switch in room for light I enter the room and flick the switch on OR off makes no difference The light will turn on for 1 second then shut off .If I wont another 1 second of light I flick the switch again .Does not matter what state it was in .It will give 1 second of light per state change
 

hippy

Ex-Staff (retired)
if pin3 = 1 then high 2 wait 1 low 2 endif
if pin3 =0 then high 2 wait 1 low 2 endif

I need it to re trigger when pin 3 changes state
Code:
Do
  Do : Loop Until pin3 = 1
  High 2 :  Wait 1 : Low 2
  Do : Loop Until pin3 = 0
  High 2 :  Wait 1 : Low 2
Loop
 

shellakaa

Member
you could use a flag to record state and use if then elseif
if on and now off
elseif off and now on

but hippy just posted quicker method.
 

newbe

New Member
Thank you all

That works ! I must have some type of learning disability Iv messed with piaxe 8 for a few years simple projects .Cant remember much of what iv read Usually copy paste similar code if I can find it Then try to alter it for my task Iv read the PDF s on the chip many many times Sometimes the rolling stone gathers no moss.Very helpful .Their should be a nominal flat fee paid to who ever posts a solution to the post like a voluntary donation button Dam now I'm in-debt. Might take some off the pain out of helping with the same old problems. Id rather give than receive for ever in your debt bas805
 

hwholmes

Member
Or you might try this where the same code does it all:

Code:
bit0 = pin3      ' store current value to avoid "first run" action
main:
   if pin3 <> bit0 then                                ' value has changed
      bit0 = pin3 : High 2 :  Wait 1 : Low 2     ' do it
   endif     goto main
 
Last edited:

Dippy

Moderator
Glad you've got a start bas.

The point I was trying to make was that if you write it down as a list with spaces and CR/LF, with all your IFs included then you'll see that the next step to BASIC isn't all that different.

Slickening it up can be more tricky but that's what people here will do for you.
 

techElder

Well-known member
You guys are saints! Any other forum and this poster would have been toast after the first post. Very patient. You should be commended, but you won't be because you are your own prize! :)
 
Top