Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.11 KB | None | 0 0
  1. #define THRESHOLD 40
  2. #define MIC SENSOR_2
  3.  
  4. bool timer = false;
  5.  
  6. sub turn(string richtung){
  7.     if(richtung == "rechts"){
  8.                 OnFwd(OUT_C,50);
  9.                 OnRev(OUT_B,50);
  10.                 Wait(700);
  11.                 Off(OUT_BC);
  12.     }
  13.     if(richtung == "links"){
  14.                 OnFwd(OUT_B,50);
  15.                 OnRev(OUT_C,50);
  16.                 Wait(700);
  17.                 Off(OUT_BC);
  18.     }
  19. }
  20.  
  21. task main(){
  22.      SetSensorSound(IN_2);
  23.      long time;
  24.      long t0;
  25.      int clap = 0;
  26.      int tmp = 0;
  27.      int direction = 0;
  28.      bool motor = false;
  29.      while(true){
  30.                  until(MIC > THRESHOLD);
  31.                  clap = 1;
  32.                  Wait(200);
  33.                  t0 = CurrentTick();
  34.                  time = CurrentTick() - t0;
  35.                  while(time < 1000){
  36.                  TextOut(5,LCD_LINE2,"Timer gestartet");
  37.                     if(MIC > tmp) tmp = MIC;
  38.                      time = CurrentTick() - t0;
  39.                  }
  40.                  TextOut(5,LCD_LINE2,"Timer beendet");
  41.                  if(tmp > THRESHOLD) clap = 2;
  42.                  if(clap == 1 && motor){
  43.                          Off(OUT_BC);
  44.                          motor = false;
  45.                  }
  46.                  else if(clap == 1 && direction == 0 && motor == false){
  47.                       OnFwd(OUT_BC,50);
  48.                       motor = true;
  49.                  }
  50.                  else if(clap == 1 && direction == 1 && motor == false){
  51.                       OnRev(OUT_BC,50);
  52.                       motor = true;
  53.                  }
  54.                  
  55.                  if(clap == 2 && motor == false){
  56.                          if(direction == 0){
  57.                                       direction = 1;
  58.                                       TextOut(5,LCD_LINE3,"Richtung: Rev");
  59.                          }
  60.                          else if(direction == 1){
  61.                                       direction = 0;
  62.                                       TextOut(5,LCD_LINE3,"Richtung: Fwd");
  63.                          }
  64.                  }
  65.                  clap = 0;
  66.                  tmp = 0;
  67.      }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement