Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.56 KB | None | 0 0
  1.  
  2. #-------------Setup----------------
  3.  
  4. import Ed
  5.  
  6. Ed.EdisonVersion = Ed.V2
  7.  
  8. Ed.DistanceUnits = Ed.CM
  9. Ed.Tempo = Ed.TEMPO_MEDIUM
  10.  
  11. #--------Your code below-----------
  12. Ed.ObstacleDetectionBeam(Ed.ON)
  13.  
  14. Ed.Drive(Ed.FORWARD,Ed.SPEED_1,Ed.DISTANCE_UNLIMITED)
  15.  
  16. def stop():
  17.     while True:
  18.         Ed.Drive(Ed.STOP, 0, 1000)
  19.  
  20. for i in range(100):
  21.     temp_score = 0
  22.     total_score = 0
  23.     if i % 4 == 1:
  24.           temp_score = 0
  25.           obstacle = Ed.ReadObstacleDetection()
  26.           if obstacle > Ed.OBSTACLE_NONE:
  27.             Ed.LeftLed(Ed.ON)
  28.             Ed.RightLed(Ed.ON)
  29.             Ed.PlayBeep()
  30.             Ed.SendIRData(10)
  31.             stop()
  32.           else:
  33.               temp_score = 0
  34.               Ed.Drive(Ed.BACKWARD,Ed.SPEED_1,10)
  35.               temp_score = victory()
  36.               total_score += temp_score
  37.               pass
  38.     elif i % 4 == 2:
  39.           temp_score = 0
  40.           obstacle = Ed.ReadObstacleDetection()
  41.           if obstacle > Ed.OBSTACLE_NONE:
  42.             Ed.LeftLed(Ed.ON)
  43.             Ed.RightLed(Ed.ON)
  44.             Ed.PlayBeep()
  45.             Ed.SendIRData(10)
  46.             stop()
  47.           else:
  48.              temp_score = 0
  49.              Ed.Drive(Ed.SPIN_RIGHT, Ed.SPEED_1, 90)
  50.              Ed.Drive(Ed.FORWARD,Ed.SPEED_1,10)
  51.              temp_score = victory()
  52.              total_score += temp_score
  53.              pass
  54.  
  55.     elif i % 4 == 3:
  56.          temp_score = 0
  57.          obstacle = Ed.ReadObstacleDetection()
  58.          if obstacle > Ed.OBSTACLE_NONE:
  59.             Ed.LeftLed(Ed.ON)
  60.             Ed.RightLed(Ed.ON)
  61.             Ed.PlayBeep()
  62.             Ed.SendIRData(10)
  63.             stop()
  64.          else:
  65.               temp_score = 0
  66.               Ed.Drive(Ed.SPIN_LEFT, Ed.SPEED_1, 90)
  67.               Ed.Drive(Ed.FORWARD,Ed.SPEED_1,10)
  68.               temp_score = victory()
  69.               total_score += temp_score
  70.               pass
  71.  
  72.     elif i % 4 ==0:
  73.           temp_score = 0
  74.           obstacle = Ed.ReadObstacleDetection()
  75.           if obstacle > Ed.OBSTACLE_NONE:
  76.             Ed.LeftLed(Ed.ON)
  77.             Ed.RightLed(Ed.ON)
  78.             Ed.PlayBeep()
  79.             Ed.SendIRData(10)
  80.             stop()
  81.           else:
  82.               temp_score = 0
  83.               Ed.Drive(Ed.FORWARD, Ed.SPEED_1, 10)
  84.               temp_score = victory()
  85.               total_score += temp_score
  86.               pass
  87.          
  88.     if total_score == 4:
  89.         while True:
  90.              Ed.PlayBeep()
  91.              Ed.Drive(Ed.SPIN_RIGHT,Ed.SPEED_1,360)
  92.  
  93. def victory():
  94.     if Ed.ReadIRData() == 10:
  95.         return 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement