Lynfield collage, picaxe code elevator, help

This is the space to ask all your burning tech questions and discuss the Skills Bright Sparks competition. We are here to help!
Post Reply
nguyenhaongnam
Posts: 1
Joined: Mon Nov 12, 2018 9:44 pm

Lynfield collage, picaxe code elevator, help

Post by nguyenhaongnam » Mon Nov 12, 2018 9:46 pm

Hey guys I'm Taea Lambert from Lynfield collage, i have here a code for one of the projects that i am working on, i have go stuck on one of the parts. When slowing down the motors my code will keep repeating the PWM each time as when the LDR's haven sensored anything it will keep repeating these 2 sections of code (in bold) any help would be great. (If you put code in picaxe editor 6 some of the words will change color and make more sense)

Thanks Taea Lambert

CODE:


int: ;in int: the code will program the LCD to project a pre-coded messedge
pause 100
serout b.6, N2400, (254,1) ;clear LCD screen
pause 100
serout b.6, N2400, (254,128) ;move Cursor to spot 128 on LCD
pause 10
serout b.6, n2400, (253, 14) ;print auto mode
pause 100
pause 50
;let pinb.5= b1 ;bottom button
;pause 50
;let pinb.4= b0 ;top button
wait 1
goto main




main:
debug
low b.7 ;telling the motor controler to make motor stop (L293D)
pause 100
low c.0 ;telling the motor controler to make motor stop (L293D)
pause 50
readadc b.0, b2 ;top LDR
pause 50
readadc b.1, b3 ;top LDR
pause 50
readadc b.2, b6 ;bottom LDR
pause 50
readadc b.3, b7 ;bottom LDR
pause 50
if pinb.4 = 1 then up ;Button On the elevator to go up
pause 50
if pinb.5 = 1 then down ;Button On the elevator to go down
pause 50
'if b16 = 1 then mode
debug
goto main


up: ;start of up code

if b2>100 and b3>100 then hault ;if both LDR's are covered goto hault
pause 100
serout b.6, n2400, (254, 192) ;go to position 1 on line 2
pause 100
serout b.6, n2400, (253, 2) ;print Going up

low b.7 ;telling the motor controler to go let motor go a certan way (L293D)
high c.0 ;telling the motor controler to go let motor go a certan way (L293D)
pause 100

if b6 < 100 then
for w10=250 to 390 step 10 ;This is the PWM section to speed up the motor
pwmout c.2, 99, w10
pause 400
debug w10
next w10
endif

pause 100

if b6 > 100 then
for w10=250 to 390 step -10
pwmout c.2, 99, w10 ;This is the PWM section to speed down the motor
pause 400
debug w10
next w10
endif

pause 100
if b7>100 and b6>100 then hault ;if both LDR's are covered goto hault
pause 100
goto up

down:
if b6>100 and b7>100 then hault ;if both LDR's are covered goto hault
pause 100
serout b.6, n2400, (254, 192) ;go to position 1 on line 2
pause 100
serout b.6, n2400, (253, 3) ;print Going up
pause 100

low c.0
high b.7
pause 100

if b6 < 100 then
for w10=250 to 390 step 10
pwmout c.2, 99, w10 ;This is the PWM section to speed up the motor
pause 400
debug w10
next w10
endif

pause 100

if b2>100 then
for w10=250 to 390 step -10
pwmout c.2, 99, w10 ;This is the PWM section to speed down the motor
pause 400
debug w10
next w10
endif

pause 100
if b2>100 and b3>100 then hault ;if both LDR's are covered goto hault
pause 100
goto down

hault:
low b.7 ;telling the motor controler to make motor stop (L293D)
pause 100
low c.0 ;telling the motor controler to make motor stop (L293D)
goto main

timchpi
Posts: 30
Joined: Wed Aug 01, 2018 11:19 am

Re: Lynfield collage, picaxe code elevator, help

Post by timchpi » Sat Nov 17, 2018 6:21 pm

Hey bro:
Glad to see someone from lynfield again. I used to be in Mr.Yearbury's class before i switch school so.
Can you try indent it so it will start make a little more sense?
Plus, try to use this:

Code: Select all

put your code like this
Regards

Post Reply