Picaxe 20M Syntax

James Barrie

New Member
I would appreciate some guidance. Being a rank novice at programming but having read the manuals I am unsure of the proper syntax in identifying input pins and output pins. My project is a simple logic requirement to detect an input when it goes low and asigning specific output pins as low or high.

Thanks in advance

Barrie
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

The general syntax is to use the pin number ( 0, 1 etc ) when using a command to control or access a pin ( HIGH, LOW, PULSIN, COUNT ) and to use the pin variable ( pin0, pin1 etc ) when wanting to know what that pin's input level is or to set it ...

High 1
Low 1
Count 1, 1000, w0

b0 = pin1
pin1 = b0
If pin1 = 0 Then
Do While pin1 = 1
 

James Barrie

New Member
Thanks for the welcome and guidance

How do you differentiate between an input pin number, output pin number and the physical component pin number


Welcome to the PICAXE forum.

The general syntax is to use the pin number ( 0, 1 etc ) when using a command to control or access a pin ( HIGH, LOW, PULSIN, COUNT ) and to use the pin variable ( pin0, pin1 etc ) when wanting to know what that pin's input level is or to set it ...

High 1
Low 1
Count 1, 1000, w0

b0 = pin1
pin1 = b0
If pin1 = 0 Then
Do While pin1 = 1
 

hippy

Technical Support
Staff member
Input pin and output pin have the same naming convention '1' or 'pin1' etc, whether input pin or output pin depends on the context of the command used - SERIN 1 is an input command so references an input pin, SEROUT 1 is an output command so references an output pin. For use of "pin1", again that's context "pin1 = b0" sets an output pn, "= pin1" reads an input pin, likewise with "If pin1 = 1 Then".

"Pin" is the name given to a PICAXE connection in or out, their location on each chip is defined in PICAXE Manual 1. To differentiate between the leg number of the chip ( also called "pin" by the industry ) we have generally adopted the terminology "leg" for referring to a physical chip leg, "pin" when referring to a software pin.

Some people disagree with this "leg" and "pin" terminology but IMO is a handy and convenient shortform; "output pin 1 is Leg 21 of a 20M" against "software output pin 1 is physical chip pin 21 of a 20M", and the temptation to shorten the later to "pin 1 is on pin 21", which is quite confusing.
 

westaust55

Moderator
@Barrie,

Welcome to the PICAXE forum.

Might I suggest that in future you post in the ACTIVE forum area at the top of the main PICAXE forum screen. You will get far more folks read your question and resopond i the Active area.

This is the Sandbox where folks usually try out ideas, etc, and is not visited by nearly as many members.
 

James Barrie

New Member
Please review my first attempt

Hippy

Would you take a look at my first steps at logic for a left right up down control of two motors providing azimuth and elevation

Thanks

Barrie


input1=b1 'input pins are b1,b2,b3,b4
input2=b2
input3=b3
input4=b4
let outpins=pins 'ouput pins are pin 1.2.3.4.5.6,7,
outpin1=pin1
outpin2=pin2
outpin3=pin3
outpin4=pin4
outpin5=pin5
outpin6=pin6
outpin7=pin7

if b1 is off then endif 'call for right turn
Let pins = %00011000 'az motor turns right
if b1 is on then endif 'call for stop
Let pins = %00000000

if b2 is off then endif 'call for left turn
Let pins = %00010100 'az motor turns lext
if b2 is on then endif 'call for stop
Let pins = %00000000


if b3 is off then endif 'call for up
Let pins = %11000000 'el motor turns up
if b3 is on then endif 'call for stop
Let pins = %00000000


if b4 is off then endif 'call for down
Let pins = %10100000 'el motor turns down
if b4 is on then endif 'call for stop
Let pins = %00000000
 

hippy

Technical Support
Staff member
Have you tried running it through the Programming Editor Simulator ?

You have a few problems -

input1=b1 'input pins are b1,b2,b3,b4

I'd guess you want it the other way round; "b0=input1" to read input1 into b1.

let outpins=pins 'ouput pins are pin 1.2.3.4.5.6,7,
outpin1=pin1


I'm less sure of what you are trying to do there, but that will set the outputs to values of input pins.

if b1 is off then endif

Won't actually achieve anything. The IF-ENDIF should wrap around one or more statements to execute when the condition is met.


The best thing to do when starting is to start simple. Get a single output working from a single input, then move on to things more complicated. For example, with a button to +V to Input Pin 1 and a pull-down to 0V, a LED+R between Output Pin 2 and 0V you can light the LED when the button is pushed with any of the following -

Code:
Do
  If pin1 = 1 Then
    High 2
  Else
    Low 2
  End If
Loop
Code:
Do
  If pin1 = 1 Then
    pin2 = 1
  Else
    pin2 = 0
  End If
Loop
Code:
Do
  pin2 = pin1
Loop
 
Last edited:

westaust55

Moderator
Don’t forget the “LOOP” command at the end of the first two examples hippy has given. Needed as shown in the third example
 

James Barrie

New Member
Good Day Hippy

Thanks for your guidance and suggestion to start simple. Interestingly the motto for our town is " Make Haste Slowly"

I have been able to get the logic sequences I need to control LEDs I have on the oututs. Now to bring all the hardware together

Thanks again

Barrie



The best thing to do when starting is to start simple. Get a single output working from a single input, then move on to things more complicated. For example, with a button to +V to Input Pin 1 and a pull-down to 0V, a LED+R between Output Pin 2 and 0V you can light the LED when the button is pushed with any of the following -
 

hippy

Technical Support
Staff member
Excellent progress and good to hear you're advancing, so good luck with the hardware.
 
Top