Advertisement
KRITSADA

Switch Case

Mar 29th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <popx2.h>
  2. int L,R,x=0,y=0;
  3. void FF(){
  4.   fd(60); sleep(300);
  5. }
  6.  
  7. void R90(){
  8.   fd(60);
  9.   sound(1500,100);
  10.   while(analog(2)>500)  {sr(60);}
  11.   while(analog(2)<500)  {sr(60);}
  12. }
  13.  
  14. void L90(){
  15.   fd(60);
  16.   sound(1500,100);
  17.   while(analog(1)>500){sl(60);}
  18.   while(analog(1)<500){sl(60);}
  19. }
  20.  
  21. void hit(){
  22.   bk(100); ao();
  23.   servo(1,180); sleep(1000);
  24.   servo(1,0);  
  25.   bk(60); sleep(200);
  26.   R90();
  27. }
  28. void setup(){
  29.   OK();
  30.   setTextSize(2);
  31.   glcdClear();
  32.   glcd(1,1,"Let’s go!");
  33. }
  34. void loop(){
  35.   L=analog(1);
  36.   R=analog(2);
  37.   if (L<500&&R<500){
  38.     x++;
  39.     switch (x){
  40.       case 1 : L90();break;
  41.       case 2 : hit();break;
  42.       case 3 : FF();break;
  43.       case 4 : hit();break;
  44.       case 5 : x=0;
  45.                y++;
  46.                if (y==4){ ao(); servo (1,-1); while(1); }
  47.     }
  48.   }
  49.   else if(L>500&&R>500){fd(60);}
  50.   else if(L<500){sl(60);sleep(20);}
  51.   else if(R<500){sr(60);sleep(20);}
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement