“摇杆”的版本间的差异
来自Labplus盛思维基百科
Tangliufeng(讨论 | 贡献) |
Jiangzhaohui(讨论 | 贡献) (→Arduino示例) |
||
第26行: | 第26行: | ||
=== <small>Arduino示例</small> === | === <small>Arduino示例</small> === | ||
<pre style="color:blue"> | <pre style="color:blue"> | ||
+ | //程序功能:根据遥感不同的值来分别控制两个LED灯// | ||
+ | // A0 A1 红灯 绿灯 // | ||
+ | // >600 >600 亮 亮 // | ||
+ | // >600 <=600 亮 灭 // | ||
+ | // <=600 >600 灭 亮 // | ||
+ | // <=600 <=600 灭 灭 // | ||
int analogAPin =A0; | int analogAPin =A0; | ||
int analogBPin =A1; | int analogBPin =A1; |
2018年1月8日 (一) 12:03的版本
概述
具有(X,Y)2轴模拟输出,可以制作遥控器用于控制运动物体的方向、速度等互动作品
技术参数
- 工作电压: VCC 3.3V -5V
- 模拟输出:0-VCC
- 模块尺寸:24x46x7.5mm
引脚定义
VCC | 电源 |
A1 | X轴模拟量 |
A0 | Y轴模拟量 |
GND | 地 |
使用教程
连接示意图
Arduino示例
//程序功能:根据遥感不同的值来分别控制两个LED灯// // A0 A1 红灯 绿灯 // // >600 >600 亮 亮 // // >600 <=600 亮 灭 // // <=600 >600 灭 亮 // // <=600 <=600 灭 灭 // int analogAPin =A0; int analogBPin =A1; int ledredPin =2; int ledbluePin =3; int a,b; void setup() { Serial.begin(9600); pinMode(analogAPin, INPUT); pinMode(analogBPin, INPUT); pinMode(ledredPin, OUTPUT); pinMode(ledbluePin,OUTPUT); } void loop() { a=analogRead(analogAPin); b=analogRead(analogBPin); Serial.println(a); if(a>600) { digitalWrite(ledredPin,HIGH); } else { digitalWrite(ledredPin,LOW); } if(b>600) { digitalWrite(ledbluePin,HIGH); } else { digitalWrite(ledbluePin,LOW); } }
MicroPython示例
# Connection: # X-Axis-->analog pin1 # Y-Axis-->analog pin0 from microbit import * while True: print('A1:',pin1.read_analog(),'A0:',pin0.read_analog()) #打印摇杆X、Y轴输出模拟量 sleep(10)