Alright, Ignore everything prior to this post, I commented all my code and I am going to explain what this is being used for so it will make more sense:
I have a vehicle that I have to program to go a certain distance between 5 to 10 meters in .5 meter increments. I will not know how far it needs to go until I need to run it, so I need it to be adjustable. I am using a 10cm wheel, so the minimum number of revolutions is 50. The .5 meter increments mean I need to increase the number of revolutions 5 times which I do by pressing the input button once per .5 meter increase from 5 meters. It then waits for me to press the button once more to start the motor so I have time to align the vehicle on the track. There is another button on the wheels that works in parallel that is pressed once every revolutions. After the number of revolutions is equal to the number of revolutions wanted, it should go into reverse for 2 milliseconds to cancel out the momentum of the vehicle.
Now the code:
The problem starts at "start". Once I press the button to start, the motor will turn on and stay on for one revolution and as soon as it is pressed one time the motor will turn off and the program will restart.
I have a vehicle that I have to program to go a certain distance between 5 to 10 meters in .5 meter increments. I will not know how far it needs to go until I need to run it, so I need it to be adjustable. I am using a 10cm wheel, so the minimum number of revolutions is 50. The .5 meter increments mean I need to increase the number of revolutions 5 times which I do by pressing the input button once per .5 meter increase from 5 meters. It then waits for me to press the button once more to start the motor so I have time to align the vehicle on the track. There is another button on the wheels that works in parallel that is pressed once every revolutions. After the number of revolutions is equal to the number of revolutions wanted, it should go into reverse for 2 milliseconds to cancel out the momentum of the vehicle.
Now the code:
Code:
#picaxe 08
Main:
let b1 = 50 `min. rev needed
high 4 `LED on, program started
pause 1000
low 4 `LED off
Counter1:
for b0=1 to 13 `Loop 13 times
high 2 `warn light, press if needed
pause 1000
low 2
if pin3 = 1 then Counter2 `Counter2 adds # of rev needed
next b0 `end loop
goto start `goto start after loops
Counter2:
high 4 `let you know it counted
let b1 = b1 + 5 `adds 5 rev
pause 1000
low 4
goto counter1 `goes back to counter
Start:
if pin3 = 0 then Start 'Wait for pin3=1
let b2 = 0 `Clear rev counter
do `Start 1st loop
do `Start 2nd loop
high 0 `turn on motor
loop until pin3 = 1 `second input is on axel/ end of 1st loop until one rev is completed
let b2= b2 + 1 `adds 1 to # of rev
loop until b2 = b1 `end of 2nd loop
low 0 `turn off motor
high 1 `put motor in reverse (instead of breaks)
pause 2
low 1
goto main `loop to beginning
Last edited: