Info
This question is closed. Reopen it to edit or answer.
Why isn't the code working?
1 view (last 30 days)
Show older comments
So, we're working on a train project, and I'm trying to write the code for getting the LED's at the railroad crossing to start flashing as soon as the train crosses the gate, and the code makes sense to me, but its not working correctly:
if a.analogRead(approach)>200
a.motorSpeed(1,200)
int=1;
left_light_int=0.5;
right_light_int=1;
tic;
toc=5;
time=1;
while time<toc
if time > left_light_int
a.digitalWrite(14,1)
a.digitalWrite(15,0)
left_light_int=left_light_int + int;
elseif time > right_light_int
a.digitalWrite(15,1)
a.digitalWrite(14,0)
right_light_int=right_light_int + int;
end
time=time+0.5
end
end
0 Comments
Answers (1)
Image Analyst
on 23 Nov 2015
Don't set toc equal to 5. It's a built-in function that returns the number of seconds since tic was called. If you want to wait 5 seconds, use pause(5). Or else use
startTime = tic;
while toc(startTime) < 5
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!