StAndrewsBB
New Member
Dear Members
I am new to Picaxe and have embarked on a project to help develop my understanding and knowledge. I am using the trainer T4 to model the automation of a roller blind for the home. I have chosen to use a stepper motor to drive the system. I have also chosen to determine the limits of movement via 2 slotted opto switches and small holes in the blind material one at either extreme of movement.
I am able to model a 2 state system in which the stepper motor drives in one direction when the light level measured by LDR is low until a switch is activated and in the reverse direction when the light level is high until a second switch is activated.
However, I would like to extend this system to 3 states, the intermediate state representing a middle light level. I've approached this by splitting the light levels and driving the motor one way or the other depending on the middle light level and stopping when both switches are activated (which I would achieve by having two small holes in the blind in the centre position).
My code works fine for the 2 state system but doesn't work for the 3 state system. I haven't currently got sufficient Picaxe knowledge to know what is wrong and whether I am fundamentally approaching this from the wrong angle.
Here is my code. I would appreciate any guidance anyone can give - with many thanks!
(Please accept my apologies if this is a trivial exercise but I guess we all have to start somewhere!)
I am new to Picaxe and have embarked on a project to help develop my understanding and knowledge. I am using the trainer T4 to model the automation of a roller blind for the home. I have chosen to use a stepper motor to drive the system. I have also chosen to determine the limits of movement via 2 slotted opto switches and small holes in the blind material one at either extreme of movement.
I am able to model a 2 state system in which the stepper motor drives in one direction when the light level measured by LDR is low until a switch is activated and in the reverse direction when the light level is high until a second switch is activated.
However, I would like to extend this system to 3 states, the intermediate state representing a middle light level. I've approached this by splitting the light levels and driving the motor one way or the other depending on the middle light level and stopping when both switches are activated (which I would achieve by having two small holes in the blind in the centre position).
My code works fine for the 2 state system but doesn't work for the 3 state system. I haven't currently got sufficient Picaxe knowledge to know what is wrong and whether I am fundamentally approaching this from the wrong angle.
Here is my code. I would appreciate any guidance anyone can give - with many thanks!
(Please accept my apologies if this is a trivial exercise but I guess we all have to start somewhere!)
Code:
dirsB=%11111111
main:
readadc C.0,b0
if b0>10 and b0<80 then OPEN ;dark and blind fully open
if b0>220 and b0<250 then CLOSE ;bright sunshine blind fully closed
if b0>100 and b0<110 then CLOSEMID ; normal light and blind closes to mid way
if b0>190 and b0<200 then OPENMID ; normal light and blind opens to mid way
goto main
OPEN:
do until pinC.7 = 1
pinsB=%00001100
pause 10
pinsB=%00000101
pause 10
pinsB=%00000011
pause 10
pinsB=%00001010
pause 10
loop
goto main
CLOSE:
do until pinC.6 = 1
pinsB=%00001010
pause 10
pinsB=%00000011
pause 10
pinsB=%00000101
pause 10
pinsB=%00001100
pause 10
loop
goto main
CLOSEMID:
do until pinC.6 = 1 and pinC.7 = 1
pinsB=%00001010
pause 10
pinsB=%00000011
pause 10
pinsB=%00000101
pause 10
pinsB=%00001100
pause 10
loop
goto main
OPENMID:
do until pinC.7 = 1 and pinC.6 = 1
pinsB=%00001100
pause 10
pinsB=%00000101
pause 10
pinsB=%00000011
pause 10
pinsB=%00001010
pause 10
loop
goto main
Last edited by a moderator: