continuous loop problem

picsammy

New Member
Hi all,
When I see the advanced coding and projects of other members, I have to say I'm a novice to picaxe programming.
Using an 08M2, I'm setting about generating a pulse between C.0 and 0v in order to switch on a 20-second voice module.
A button switch between +5v and C.3, when pressed once should turn on the module, and a 20 second pause is allowed
while the module plays. Following a pause, a tune outputs on C.4 (tune 4, 12, ($14) ).
Then loops back to start. But I want the function to wait until the button is pressed once before continuing to play the module
recording, and the tune. Then back to start again. You get the picture.
Any help welcome.
 

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

You can use the following to detect if a button is pressed then released ( gone high then returned low ) -

Do : Loop Until pinC.3 = 1
Do : Loop Until pinC.3 = 0

So you can probably use that in your main loop ...

Code:
Do
  Do : Loop Until pinC.3 = 1
  Do : Loop Until pinC.3 = 0
  [i]Do first thing[/i]
  Do : Loop Until pinC.3 = 1 
  Do : Loop Until pinC.3 = 0
  [i]Do second thing[/i]
Loop
 

AllyCat

Senior Member
Hi,

Yes, welcome to the forum.

generating a pulse between C.0 and 0v in order to switch on a 20-second voice module.
Is it an "active high" or "active low" pulse and how long does it need to last? But personally I wouldn't use pin c.0 (particularly to control an external module) because that's the serial/programming output pin and may cause strange effects.

The switch will need a pulldown resistor for reliable operation. Note that code such as hippy's actually detects when the button is released. But again, personally I would connect the switch between ground and the "input only" pin c.3. There's no risk of damage if the pin is accidentally made an output, but you can activate an input pullup resistor on that pin with a PULLUP 8 command.

Cheers, Alan.
 

picsammy

New Member
Hi there,
Thank you Hippy for solving my looping problem.
AllyCat, I note your comments and suggestions. I haven't made the pcb for the project yet, so can apply your advice when I do. Many thanks.
 
Top