Code help?

tmack

Member
I am looking for an idea how I can program an 18x so that when I press a button for x amount of time the picaxe will measure it, then when an input is triggered it will make an led go high for the same x amount of time. I haven't really used variables before so Any help would be greatly appreciated. Thank you so much.
 

lbenson

Senior Member
It might clarify your thinking if you outline the steps you need to take, e.g.

1 detect pushbutton1 pressed, note time, debounce
2 detect pushbutton1 released, note time, calculate difference
3 detect pushbutton2 pressed, etc.

Then research timer issues. If you are using X1 parts, womai's posting in code snippits can be built upon to give you the timing you need: http://www.picaxeforum.co.uk/showthread.php?t=8541

Hippy's site also has timer examples and is invaluable for all things PICAXE: http://www.hippy.freeserve.co.uk/picaxeqa.htm

For M- or X-series chips, you could look at the timer code by bflavory in this thread: http://www.picaxeforum.co.uk/showthread.php?t=5849

You could also search the forum for "timer" and related words. You will get a lot of material to sift through--part of the research process.

Work up slowly and post your code if you get stuck. For instance, you might start by detecting the pushbuttons and using an arbitrary time for the LED to be on. Then develop your timing routines. To get the best results you will need to use interrupts--a complicated issue and one which may take thought and experiment to get your head around.
 
Last edited:
Top