Raspberry pi 4, DC motor, oled
- 아래의 사진에서 우측에 있는 버튼은 oled와 모터의 전원을 제어하고, 좌측에 있는 버튼은 모터의 속도를 제어함
- adafruit의 circuit python 모듈을 사용하여 개발
import time
import subprocess
from xmlrpc.client import boolean
from board import SCL, SDA
import busio
from PIL import Image, ImageDraw, ImageFont
import time
from adafruit_motorkit import MotorKit
import adafruit_ssd1306
import board
import digitalio
#Motor Speed
switch_pin = board.D16 #power
motor_pin = board.D17 #motor
kit = MotorKit()
power_switch = digitalio.DigitalInOut(switch_pin)
motor_speed_switch = digitalio.DigitalInOut(motor_pin)
power_switch.direction = digitalio.Direction.INPUT
power_switch.pull = digitalio.Pull.UP
motor_speed_switch.direction = digitalio.Direction.INPUT
motor_speed_switch.pull = digitalio.Pull.UP
power1 = True
speed1 = 0.5
i2c = busio.I2C(SCL, SDA)
disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
while True:
if not power_switch.value:
# print('button1')
power1 = not power1
if power1:
kit.motor1.throttle = 0
disp.poweroff()
if not power1:
kit.motor1.throttle = speed1
disp.poweron()
disp.fill(0)
disp.show()
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
draw = ImageDraw.Draw(image)
draw.rectangle((0, 0, width, height), outline=0, fill=0)
padding = -2
top = padding
bottom = height-padding
x = 0
font = ImageFont.load_default()
draw.rectangle((0, 0, width, height), outline=0, fill=0)
cmd = "hostname -I | cut -d\' \' -f1"
IP = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'"
CPU = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%s MB %.2f%%\", $3,$2,$3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%d GB %s\", $3,$2,$5}'"
Disk = subprocess.check_output(cmd, shell=True).decode("utf-8")
draw.text((x, top+0), "IP: "+IP, font=font, fill=255)
draw.text((x, top+8), CPU, font=font, fill=255)
draw.text((x, top+16), MemUsage, font=font, fill=255)
draw.text((x, top+25), Disk, font=font, fill=255)
disp.image(image)
disp.show()
if not motor_speed_switch.value:
# print('button2')
if speed1 == 1.0:
speed1 = 0.5
kit.motor1.throttle = speed1
# print(speed1)
else:
speed1 += 0.5
kit.motor1.throttle = speed1
# print(speed1)
time.sleep(0.1)
'Old > 프로젝트 결과물' 카테고리의 다른 글
메타버스 디자인 기획 - MyVox 플랫폼 기획서 (0) | 2023.12.14 |
---|---|
가상현실게임 - Virtual Singer (0) | 2023.12.14 |
메타버스 UX 디자인 - MyVox (0) | 2023.12.14 |
메타버스 게임 디자인 - 최종 (0) | 2023.06.10 |
체감형 AR 디자인 - 최종 (0) | 2023.06.04 |