View Single Post
  #10   Spotlight this post!  
Unread 09-04-2014, 15:50
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: How to loop peices of code forever?

I don't know your level of knowledge so I can give you an appropriately tailored answer. My first thought is that this should be implemented as a state machine without any delays in it. The "start" state would do nothing, and would move to the "follow the line forward" when it sees the button press. When not in the "start" state I'd have the program continually check to see whether the button has just been pressed, and set a "prepare to stop" flag if so. If the flag is set, the final "drop the block" state would transition either to a "halted" state or back to the "start" state if you want to be able to start it up again.

Doing it sequentially with delays, as in the originally posted code, will make detecting the second button press very difficult.