Reading from a pot.

shamu

Member
Hi all.
I am trying to read an analogue value from a variable resistor, my code looks like this and simulates fine:
main:
readadc 0, b1
'b1 =21
if b1 > 20 then high 0
else
low 0
end if
goto main


My question is this, which physical pin of my 18M do I read from, the manual appears to suggest pin 18 but isn't this a digital input?

Thanks.
 

SAborn

Senior Member
When you say 18m, i take it you mean 18m2 picaxe chip

In your code .....readadc 0, b1....... you are saying readadc, pin0.

This wont work for the 18m2 as you need to list the pin number differently.
You could use ...readadc C.0, b1 and this would be physical pin 17
or if you want to use physical pin 18 then it would be ...readadc C.1, b1

As for what pins to use you can use any of the adc inputs, C.2, C.1, C.0, B.1, B.2, B.3, B.4, B.5, B.6, B.7

Also in your code there is a error ....if b1 > 20 then high 0
this should read........

if b1 > 20 then
high 0

the high 0 .. should be on the second line and not directly after the "then".
 

hippy

Technical Support
Staff member
readadc 0, b1

My question is this, which physical pin of my 18M do I read from, the manual appears to suggest pin 18 but isn't this a digital input?
You need to consult the pinout diagram in PICAXE Manual 1. You are reading ADC channel 0 and the ADC 0 input is on leg 17. This leg is a digital input ( input pin 0 ) with analogue input capability ( ADC 0 ), so it can be used for either.
 
Top