123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #!/usr/bin/env python
- #version : 2023.12.31
- #language : ch
- #hardware : pi
- from maix import display
- from maix import image
- from maix import camera
- import smbus2
- import time
- import sys
- sys.path.append("/root/")
- from CocoPi import stm8s
- iic_slaver=stm8s()
- iic_slaver.clear()
- del iic_slaver
- from CocoPi import dcMotor
- from CocoPi import BUTTON
- key_D = BUTTON(7)
- key_B = BUTTON(8)
- key_C = BUTTON(13)
- D1=dcMotor(1)
- D2=dcMotor(2)
- image.load_freetype("/root/preset/fonts/SourceHanSansCN-Regular.otf")
- camera.camera.config(size=(320,240))
- ScreenOrientation = False
- speed=0
- rotation=1
- addValue=1
- angle=0
- canvas = image.new(size = (320, 240))
- while True:
- if (key_B.is_pressed()):
- while key_B.is_pressed():
- time.sleep(0.001)
- rotation=(-1)*rotation
- if(key_C.is_pressed()):
- if speed<255:
- addValue=1
- else:
- addValue=0
- elif key_D.is_pressed():
- if speed>0:
- addValue=-1
- else:
- addValue=0
- else:
- addValue=0
- canvas = image.new(color=(0,0,0),size = (320, 240))
-
- speed=speed+addValue
- canvas.draw_string(80, 8, "转速:"+str(speed), 1, color=(0, 255, 0))
- if rotation==1:
- canvas.draw_image((image.open("/root/preset/img/clockwise_bfbfbf_24x24.png")).rotate(0, adjust=0),8,216,alpha=1)
- #canvas.draw_string(40, 24, "rotation:clockwise", 1, color=(0, 255, 0))
- else:
- canvas.draw_image((image.open("/root/preset/img/anticlockwise_bfbfbf_24x24.png")).rotate(0, adjust=0),8,216,alpha=1)
- #canvas.draw_string(40, 24, "rotation:anticlockwise", 1, color=(0, 255, 0))
- angle=angle-int(rotation*speed/3)
- if angle>3600:
- angle=angle-3600
- elif angle<-3600:
- angle=angle+3600
- else:
- angle=angle
- #canvas.draw_string(4, 180, "C:change fan's direction of rotation", 1, color=(0, 255, 0))
- #canvas.draw_string(4, 200, "D:increase fan's speed of rotation", 1, color=(0, 255, 0))
- #canvas.draw_string(4, 220, "B:decrease fan's speed of rotation", 1, color=(0, 255, 0))
- canvas.draw_image((image.open("/root/preset/img/ttMotor_200_64.png")).rotate(0, adjust=1),80,90,alpha=1)
- canvas.draw_image((image.open("/root/preset/img/fan_140_140.png")).rotate(angle, adjust=0),60,52,alpha=1)
- canvas.draw_image((image.open("/root/preset/img/increase_bfbfbf_24x24.png")).rotate(0, adjust=0),288,8,alpha=1)
- canvas.draw_image((image.open("/root/preset/img/decrease_bfbfbf_24x24.png")).rotate(0, adjust=0),8,8,alpha=1)
- canvas.draw_image((image.open("/root/preset/img/exit_ff0000_24x24.png")).rotate(0, adjust=0),288,216,alpha=1)
- if(speed<80):
- D1.dcMotorCtrl(rotation,speed)
- D2.dcMotorCtrl(rotation,speed)
- else:
- if rotation==1:
- D1.dcMotorCtrl(1,speed)
- D2.dcMotorCtrl(1,speed)
- else:
- D1.dcMotorCtrl(0,speed)
- D2.dcMotorCtrl(0,speed)
- time.sleep(0.004)
- if ScreenOrientation:
- canvasVER = canvas.crop(0,0,240,320)
- canvasVER = canvasVER.rotate(-90, adjust=1)
- display.show(canvasVER)
- else:
- display.show(canvas)
|