【RPi PICO】在ms_paint中绘画

树莓派 PICO 和 RP2040 相关应用讨论
回复
头像
shaoziyang
帖子: 3951
注册时间: 2019年 10月 21日 13:48

【RPi PICO】在ms_paint中绘画

#1

帖子 shaoziyang »

  1. 需要先刷入circuitpython固件,然后从adafruit绑定库中复制adafruit_hid到板子的lib目录。
  2. 将下面的代码保存到板子的code.py中并退出磁盘后重新插入。
  3. 再运行windows的画图软件(其它一些绘图软件也可能支持,例如PS),并切换到铅笔工具,用镊子短连GPIO16和GND,就会开始自动绘图了。

Code: Select all

# Emulate mouse to draw Chord on the computer screen! by Hari Wiguna, Jan 2021
import time
import board
import digitalio
import usb_hid
from adafruit_hid.mouse import Mouse
import math

class Point:
def __init__(self, xx, yy):
self.x = xx
self.y = yy

numNodes = 7
radius = 50
nodes = []

origin = Point(0, 0)
pen = Point(0, 0)

mouse = Mouse(usb_hid.devices)

class code:
def __init__(self):
self.btn = digitalio.DigitalInOut(board.GP16)
self.btn.direction = digitalio.Direction.INPUT
self.btn.pull = digitalio.Pull.UP

# compute points
for i in range(numNodes):
a = math.pi * 2 * i / numNodes
x = origin.x + math.cos(a) * radius
y = origin.y - math.sin(a) * radius # minus because computer screen origin is top left
nodes.append(Point(x,y))

def moveto(self,p):
global pen
dx = p.x - pen.x
dy = p.y - pen.y
mouse.move(x=int(dx), y=int(dy))
pen = p
time.sleep(0.005)

def plotto(self,p):
mouse.press(Mouse.LEFT_BUTTON)
self.moveto(p)
mouse.release_all()

def main(self):
global pen
while True:
if self.btn.value == False:
pen = Point(0,0)
for i in range(numNodes-1):
for j in range(i+1, numNodes):
self.moveto(nodes[i])
self.plotto(nodes[j])

app = code()
app.main()
这个例子来自:https://hackaday.io/project/177200-pi-p ... n-ms-paint
 
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章