how do I?..

fathom

New Member
Long time lurker first time poster!!

Been playing about with the picaxe experimenter board with the 18X i got for xmas.

Haven't played with microcontrollers since the mid 90's when it was .asm code. So a couple of questions....

First of all how do i put a input into a register (ie PIN0 into b1) so I can use it later. I would have done it with 'push' in asm but can't seem to find out how to do it in the tutorial guides

Secondly, I wrote a program so when a button was pushed a lamp would light but first go from off to full brightness via a PWM subroutine, but I want the light to stay lit at full brightness until I let go of the button. As at the moment once the subroutine has finished it will loop back to the start. I suspect its a stupid mistake but any help would be appreciated.

main:

if pin0 = 1 then lit 'if SW1 is pressed goto lit
if pin0 = 0 then unlit 'if SW1 is not pressed goto unlit
goto main

lit:

gosub brightup
high 1
goto main

unlit:

low 0
goto main

brightup:

for b1 = 1 to 400
pwmout 3,99,b1
pause 10
next b1

goto main
Thanks in advance.
 
Last edited:

eclectic

Moderator
@fathom.

Welcome to the Forum.

Could you post your program,
then, I'm sure that you'll receive
plenty of help.

e

And I look back, and it's done! :))
Amazing!

First things first:

You'll need a Word variable.
So, change b1 to say W1
 
Last edited:

hippy

Technical Support
Staff member
To put a pin level into a variable ( register ), simply use 'b3 = pin6' for example. This will set 'b3' to either 0 or 1 depending on the input level on Input Pin 6.

The same can be done for output; 'pin5 = 1' is equivalent to 'HIGH 5' and 'pin5 = 0' equivalent to 'LOW 5'. The value can come from a variable, 'pin5 = b1' where the Output Pin level will be set to the lsb of value of the variable, 0 is Low (0V), 1 is High (+V).
 

fathom

New Member
changed the program

main:

if pin0 = 1 then lit 'if SW1 is pressed goto lit
if pin0 = 0 then unlit 'if SW1 is not pressed goto unlit
goto main

lit:

gosub brightup
high 1
goto main

unlit:

low 1
goto main

brightup:

for b1 = 1 to 400
pwmout 3,99,b1
pause 10
next b1
return
the program now runs but when the button is released the pwm subroutine continues to run, how do I get it to run just the once?

Also regards to the first question what basic command to I use to push the PIN0 value into the W1 register?

Sorry missed hippy's post had to swing the TV aerial again! Knew it had to be simple!!
 

lbenson

Senior Member
This doesn't do the ramping, but try this in the simulator to see how you can put a pin value into a bit variable (bit0, for instance, which is part of b0 which is part of w0).
Code:
#picaxe 08M

main:
  bit0 = pin3
  if bit0 = 1 then
    sertxd("button is on",cr,lf)
  else
    sertxd("button is off",cr,lf)
  endif
  do : loop while bit0 = pin3 ' wait until it changes
  goto main
 

hippy

Technical Support
Staff member
I think the main problem you are having is doing a loop rather than waiting for this, do that, wait for something else, do something else ...

Code:
Do
  Wait for button push
  Ramp Up
  Wait for button release
  Turn Off
Loop
You can wait for a pin level using "Do : Loop Until pinX = Y" ( and use While , and <>, to fit your preferences ), so something along the lines of ...

Code:
Do
  Do : Loop until pin0 = 1
  For w0 = 1 to 400
    PwmOut 3, 99, w0
    Pause 10
  Next
  Do : Loop Until pin0 = 0
  [i]... Turn Off ...[/i]
Loop
 

fathom

New Member
interesting....

I'm just messing around with various programs in an effort to learn what the picaxe can do thanks for your help.

Need to re read the if/else/do/loop commands
 
Top