Advertisement
Lonely_Wanderer

Полное управление джойстиком

Sep 26th, 2023
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.19 KB | None | 0 0
  1. from m5stack import *
  2. from m5ui import *
  3. from uiflow import *
  4.  
  5. setScreenColor(0x222222)
  6.  
  7. rectangle0 = M5Rect(145, 105, 30, 30, 0xFFFFFF, 0xFFFFFF)
  8. joystick = unit.get(unit.JOYSTICK, unit.PORTA)
  9. x=145
  10. y=105
  11. while True:
  12.   if joystick.Y<=260 and  joystick.Y>=220 and joystick.X<140 and joystick.X>110:
  13.     y=y-1
  14.     rectangle0.setPosition(x,y)
  15.     wait(0.1)
  16.   elif joystick.Y<=30 and  joystick.Y>=0 and joystick.X<140 and joystick.X>110:
  17.     y=y+1
  18.     rectangle0.setPosition(x,y)
  19.     wait(0.1)
  20.   elif joystick.X<=260 and  joystick.X>=220 and joystick.Y<=140 and joystick.Y>=110:
  21.     x=x+1
  22.     rectangle0.setPosition(x,y)
  23.     wait(0.1)
  24.   elif joystick.X<=30 and  joystick.X>=0 and joystick.Y<140 and joystick.Y>110:
  25.     x=x-1
  26.     rectangle0.setPosition(x,y)
  27.     wait(0.1)
  28.   elif joystick.X<=110 and  joystick.X>=0 and joystick.Y<=150 and joystick.Y>125:
  29.     x=x-1
  30.     y=y-1
  31.     rectangle0.setPosition(x,y)
  32.     wait(0.1)
  33.   elif joystick.X<=110 and  joystick.X>=0 and joystick.Y<=180 and joystick.Y>150:
  34.     x=x-1
  35.     y=y-2
  36.     rectangle0.setPosition(x,y)  
  37.     wait(0.1)
  38.   elif joystick.X<=110 and  joystick.X>=0 and joystick.Y<=210 and joystick.Y>180:
  39.     x=x-1
  40.     y=y-3
  41.     rectangle0.setPosition(x,y)
  42.     wait(0.1)
  43.   elif joystick.X<=110 and  joystick.X>=0 and joystick.Y<=260 and joystick.Y>210:
  44.     x=x-1
  45.     y=y-4
  46.     rectangle0.setPosition(x,y)  
  47.     wait(0.1)
  48.   elif joystick.X<=110 and  joystick.X>=0 and joystick.Y<=115 and joystick.Y>90:
  49.     x=x-1
  50.     y=y+1
  51.     rectangle0.setPosition(x,y)
  52.     wait(0.1)
  53.   elif joystick.X<=110 and  joystick.X>=0 and joystick.Y<=90 and joystick.Y>60:
  54.     x=x-1
  55.     y=y+2
  56.     rectangle0.setPosition(x,y)  
  57.     wait(0.1)
  58.   elif joystick.X<=110 and  joystick.X>=0 and joystick.Y<=60 and joystick.Y>30:
  59.     x=x-1
  60.     y=y+3
  61.     rectangle0.setPosition(x,y)
  62.     wait(0.1)
  63.   elif joystick.X<=110 and  joystick.X>=0 and joystick.Y<=30 and joystick.Y>0:
  64.     x=x-1
  65.     y=y+4
  66.     rectangle0.setPosition(x,y)  
  67.     wait(0.1)
  68.   elif joystick.X<=240 and  joystick.X>=130 and joystick.Y<=150 and joystick.Y>125:
  69.     x=x+1
  70.     y=y-1
  71.     rectangle0.setPosition(x,y)
  72.     wait(0.1)
  73.   elif joystick.X<=240 and  joystick.X>=130 and joystick.Y<=180 and joystick.Y>150:
  74.     x=x+1
  75.     y=y-2
  76.     rectangle0.setPosition(x,y)  
  77.     wait(0.1)
  78.   elif joystick.X<=240 and  joystick.X>=130 and joystick.Y<=210 and joystick.Y>180:
  79.     x=x+1
  80.     y=y-3
  81.     rectangle0.setPosition(x,y)
  82.     wait(0.1)
  83.   elif joystick.X<=240 and  joystick.X>=130 and joystick.Y<=260 and joystick.Y>210:
  84.     x=x+1
  85.     y=y-4
  86.     rectangle0.setPosition(x,y)  
  87.     wait(0.1)
  88.   elif joystick.X<=240 and  joystick.X>=130 and joystick.Y<=115 and joystick.Y>90:
  89.     x=x+1
  90.     y=y+1
  91.     rectangle0.setPosition(x,y)
  92.     wait(0.1)
  93.   elif joystick.X<=240 and  joystick.X>=130 and joystick.Y<=90 and joystick.Y>60:
  94.     x=x+1
  95.     y=y+2
  96.     rectangle0.setPosition(x,y)  
  97.     wait(0.1)
  98.   elif joystick.X<=240 and  joystick.X>=130 and joystick.Y<=60 and joystick.Y>30:
  99.     x=x+1
  100.     y=y+3
  101.     rectangle0.setPosition(x,y)
  102.     wait(0.1)
  103.   elif joystick.X<=240 and  joystick.X>=130 and joystick.Y<=30 and joystick.Y>0:
  104.     x=x+1
  105.     y=y+4
  106.     rectangle0.setPosition(x,y)  
  107.     wait(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement