1. while (true)
  2. {
  3. //Get Ping Distance (front of car)
  4. ForwardDistance = ForwardPing.GetDistance(Parallax.Components.Ping.DistanceUnits.Inches);
  5. Debug.Print(ForwardDistance.ToString());
  6.  
  7. //Drive forward while distance is 2ft or more, drive forward and straight
  8. //When closer than 2ft back up and turn, then repeat
  9. if (ForwardDistance >= 24)
  10. {
  11. Futaba.SetPosition(100);
  12. Rooster.Drive();
  13. }
  14. else //Stop car, turn wheels to the left, reverse for one second at lowest speed
  15. {
  16. Rooster.Stop(); // this doesnt exactly stop, just cuts motor drive, so it may still ram into things
  17. Futaba.SetPosition(80);
  18. Rooster.Reverse();
  19. Thread.Sleep(1000);
  20. }
  21. }