Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Simple PICAXE problem

Status
Not open for further replies.
Hi guys, I'm a complete newbie in the world of PICAXE.

I want to make something (haven't really decided what yet) which responds to IR.

My program:


# picaxe 08m2


irin C.3, infra

main:
irin [1000, main], C.3, b0 ;wait for new signal

if b0= 1
then swon1 ;switch on 1

if b0 = 2
then swon2 ;switch on 2

if b0 = 3
then swon3 ;switch on 3

goto main

swon1: high C.0
pause 250
low C.0

swon2: high C.1
pause 250
low C.1

swon3: high C.2
pause 250
low C.2


When I do a syntax check, it tells me that "if b0 = 1" is a syntax error.

I realise this may be a really simple answer, but this has completely stumped me!! :)
Thanks for your time ;)
 
Perhaps you need capitals?

If b0 = 1 Then
swon1

Also, to save instruction cycles you should use ElseIf.

If b0 = 1 Then
swon1 ;switch on 1

ElseIf b0 = 2 Then
swon2 ;switch on 2

ElseIf b0 = 3 Then
swon3 ;switch on 3

End If
 
Last edited:
Hi Gobbledok. Thanks for the input, but unfortunately it does not work. :(

Isn't BASIC not case-sensitive? Meaning it won't make a difference.

And I can see what you mean by using elseif, thanks for the suggestion.

Sorry to ask, but do you have any other suggestions???
 
Just had a quick read.. You are right, BASIC is case insensitive. I have only -dabbled- in BASIC and am more of a C person myself.

So due to lack of familiarity I can't help you any further but the only other glaring thing I would check is that the port you want is definitely called b0.
 
Ok thanks for your time anyway, I will definitely check b0.

I have tried to learn C, and I struggled a lot, I think after learning BASIC a lot of the concepts in C became a lot easier to understand.

Thanks again for your time. :)
 
There no way you can check B0 for 2,3 etc all you can check for is 1 or 0 high or low

To check for 3 presses you need a counter like

Code:
       If PIN0 = 1 then
	  inc i
       else
        i=i
      endif
      If i =1 
        then ''do something 
      elseif 
      i=2
       then ''do this
I would use PIN it sets the pin as input

When using inputs the input variable (pin1, pin2 etc) must be used (not the actual pin name 1, 2 etc.) i.e. the line must read 'if pin1 = 1 then...', not 'if 1 = 1 then...'

Some PICAXE parts have additional inputs on porta and portc. To read the state of PORTA and PORTC pins on the older 28X/X1 parts, they keyword PORTA or PORTC is inserted after IF to redirect the whole line to the desired port. For newer parts use the direct PORT.PIN notation instead e.g. if pinC.1 = 1 then....

When using PORTA or PORTC keywords, it is possible to use AND and OR within the command, but all pins tested will be on the same port, it is not possible to mix ports within one line.

The if...then command only checks an input at the time the command is processed. Therefore it is normal to put the if...then command within a program loop that regularly scans the input. For details on how to permanently scan for an input condition using interrupts see the 'setint' command.

To read the whole input port at once the variable 'pins' can be used if pins = %10101010 then gosub label. To read the whole input port and mask individual inputs (e.g. 6 and 7) let b1 = pins & %11000000, if b1 = %11000000 then gosub label.

The words is (=), on (1) and off (0) can also be used with younger students.
 
Do this:-

if b0 = 1 then swon1 ;switch on 1

if b0 = 2 then swon2 ;switch on 2

if b0 = 3 then swon3 ;switch on 3

then it will be OK
 
be08be, thanks for the comment. However it did not work for me. I am not sure why, but I know this is through my own fault.

Piiko, I have a confession. Earlier, I glanced over your comment and decided the program you gave me was the same as my own and disregarded it. After half an hour or so of successive syntax errors, I became desperate. I looked over your answer again and saw that "then swon1" is on the same line as "if b0 = 1". I tried it with SUCCESS. You have my thanks and most humble apologies of that moment of hot-headedness. ;)

My new code:

# picaxe 08m2


irin C.3, infra

main:
irin [1000, main], C.3, b0 ;wait for new signal

if b0= 1 then swon1 ;switch on 1

if b0 = 2 then swon2 ;switch on 2

if b0 = 3 then swon3 ;switch on 3

goto main

swon1: high C.0
pause 250
low C.0

swon2: high C.1
pause 250
low C.1

swon3: high C.2
pause 250
low C.2

It works :)

However, I have a new question:

"if b0 = 1
then swon1" - throws up a syntax error

"if b0 = 1 then swon1" - is perfectly fine.

Why? Surely the new line is just whitespace and is ignored.

My original question has been solved, I am just curious as to why the original program was wrong.

Thanks again for your time :) I really do appreciate it
 
I think it's because "if---then" is classified as a single command and therefore must be on the same line.
 
Ok thank you

EDIT: Using irout, how do I transmit information to be received by irin? I know this is a big question. I'll give an example,

IRIN:
irin C.3, infra

main:
irin [1000, main], C.3, b0 ;wait for new signal
if b0= 1 then swon1
goto main
etc...

If I want to make C.5 (on a different chip) high, which then transmits irout so that irin can receive and output a value of 1, what must I do???

I'm sorry to keep asking questions, but I'm completely new to this... :roll eyes:

EDIT 2: Ok I found a basis for this, but am still stuck:

for b1 = 1 to 10
irout 1,1,5
pause 45
next b1

I am confused about the "for b1 = 1 to 10". How do I give b1 a value 1 to 10? And if I want to give b1 to change, lets say by making another pin high on the chip, can I change the value of b1 to transmit other data???

Ok, I think I solved it:

# picaxe 08m2

output C.0
input C.1


main:
let b1 = C.1 ;value of C.1 is stored in b1

if b1 = 1 then irout 1,1,5 ;if C.1 goes high, b1 = 1 and irout transmits data 5
pause 20 ;pause for 0.2 to increase realibility (I think)
endif
goto main ; goes back to main

Not sure if this will work. Opinions???

Thanks again for your time.
 
Last edited:
That's what got me when you first posted I was thinking B1 is a pin but it's a variable. And your using commands irin and such.

You really should have a look at the online list of commands. https://www.picaxe.com/BASIC-Commands if you haven't it's great
 
Thanks be08be (Burt?). I have looked at the BASIC commands, and it was helpful. But in this case, I'm taking BASIC as I go along. The manuals are fairly structured, so missing key elements is difficult. Thanks for the link though. I guess the only REAL way to test this is by actually applying it. I'll re-post if anything goes awry.

Thanks to everyone for their suggestions, they are all appreciated :)
 
Ok guys. Sorry to bring up something that's supposed to be solved, but it doesn't work.

I'll just ask a different question.

Does anyone have a code or a link to a code for irin and irout??? Whatever I try doesn't work.

Sorry for the old post, and thanks to anyone who can help with my misery.
 
This is irin
Code:
main:	irin [1000,main],C.3,b0	; wait for new signal
	if b0 = 1 then swon1	; switch on 1
	if b0 = 4 then swoff1	; switch off 1
	goto main

swon1:	high B.1
	goto main
swoff1:	low B.1
	goto main


This is irout
Code:
for b1 = 1 to 10
	  irout B.1,1,5
	  pause 45
	next b1
 
Also --- check out the Picaxe Forum, there are lots of helpfull people there.

**broken link removed**

pilko
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top