10_servoControl.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. #version : 2023.06.0`
  3. #language : en
  4. #hardware : pi
  5. from maix import display
  6. from maix import image
  7. from maix import camera
  8. import time
  9. import sys
  10. sys.path.append('/root/')
  11. from CocoPi import BUTTON
  12. from CocoPi import multiFuncGpio
  13. S1=multiFuncGpio(0,1)
  14. S2=multiFuncGpio(1,1)
  15. key_D = BUTTON(7)
  16. key_C = BUTTON(13)
  17. camera.camera.config(size=(320,240))
  18. ScreenOrientation = False
  19. angle=0
  20. addValue=0
  21. image.load_freetype("/root/preset/fonts/CascadiaCodePL-Italic.ttf")
  22. canvas = image.new(size = (320, 240))
  23. while True:
  24. if(key_C.is_pressed()):
  25. if angle<180:
  26. addValue=1
  27. else:
  28. addValue=0
  29. elif key_D.is_pressed():
  30. if angle>0:
  31. addValue=-1
  32. else:
  33. addValue=0
  34. else:
  35. addValue=0
  36. canvas = image.new(color=(0,0,0),size = (320, 240))
  37. angle=angle+addValue
  38. #canvas.draw_string(4, 180, "C:increase servo's angle", 1, color=(0, 255, 0))
  39. #canvas.draw_string(4, 200, "D:decrease servo's angle", 1, color=(0, 255, 0))
  40. canvas.draw_string(80, 10, "servo angle:"+str(angle), 1, color=(0, 0, 255))
  41. canvas.draw_image((image.open("/root/preset/img/sg90.png")).rotate(0, adjust=1),132,70,alpha=1)
  42. canvas.draw_image((image.open("/root/preset/img/sg90_double_arm.png")).rotate(angle, adjust=0),103,89,alpha=1)
  43. canvas.draw_image((image.open("/root/preset/img/increase_bfbfbf_24x24.png")).rotate(0, adjust=0),288,8,alpha=1)
  44. canvas.draw_image((image.open("/root/preset/img/decrease_bfbfbf_24x24.png")).rotate(0, adjust=0),8,8,alpha=1)
  45. canvas.draw_image((image.open("/root/preset/img/exit_ff0000_24x24.png")).rotate(0, adjust=0),288,216,alpha=1)
  46. S1.servoCtrl(angle)
  47. S2.servoCtrl(angle)
  48. if ScreenOrientation:
  49. canvasVER = canvas.crop(0,0,240,320)
  50. canvasVER = canvasVER.rotate(-90, adjust=1)
  51. display.show(canvasVER)
  52. else:
  53. display.show(canvas)