摇杆
概述
具有(X,Y)2轴模拟输出,可以制作遥控器用于控制运动物体的方向、速度等互动作品。
技术参数
工作电压: VCC 3.3V -5V
模块尺寸:24*48mm
固定安装:2个兼容塑料积木通孔
数据类型:模拟采样值
引脚定义
引脚 |
定义 |
|---|---|
GND |
地 |
VCC |
电源 |
A1 |
X轴模拟采样值 |
A2 |
Y轴模拟采样值 |
示例程序
用摇杆进行上下左右操控时,掌控板OLED屏显示对应的方向。
from mpython import *
p0 = MPythonPin(0, PinMode.ANALOG)
p1 = MPythonPin(1, PinMode.ANALOG)
import time
while True:
oled.fill(0)
oled.DispChar(str('方向为: '), 0, 0, 1)
oled.show()
if p0.read_analog() < 1000:
oled.fill(0)
oled.DispChar(str('方向为: 上'), 0, 0, 1)
oled.show()
time.sleep(0.2)
if p1.read_analog() > 2500:
oled.fill(0)
oled.DispChar(str('方向为: 右'), 0, 0, 1)
oled.show()
time.sleep(0.2)
if p0.read_analog() > 2500:
oled.fill(0)
oled.DispChar(str('方向为: 下'), 0, 0, 1)
oled.show()
time.sleep(0.2)
if p1.read_analog() < 1000:
oled.fill(0)
oled.DispChar(str('方向为: 左'), 0, 0, 1)
oled.show()
time.sleep(0.2)