“排风扇”的版本间的差异
来自Labplus盛思维基百科
Labplus课程组(讨论 | 贡献) (→MicroPython示例) |
Labplus课程组(讨论 | 贡献) |
||
第19行: | 第19行: | ||
== 使用教程 == | == 使用教程 == | ||
+ | === Arduino示例 === | ||
+ | <pre style="color:blue"> | ||
+ | //程序功能:按键按下,风扇转动;按键松开,风扇停止// | ||
+ | int buttonPin =2; | ||
+ | int fanPin=3; | ||
+ | int val; | ||
+ | void setup() { | ||
+ | // put your setup code here, to run once: | ||
+ | Serial.begin(9600); | ||
+ | pinMode(buttonPin,INPUT); | ||
+ | pinMode(fanPin,OUTPUT); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | val=digitalRead(buttonPin); | ||
+ | Serial.print(val); | ||
+ | if(val==HIGH) | ||
+ | { | ||
+ | digitalWrite(fanPin,HIGH); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | digitalWrite(fanPin,LOW); | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
=== MicroPython示例 === | === MicroPython示例 === | ||
<pre style="color:blue"> | <pre style="color:blue"> |
2018年4月20日 (五) 17:20的版本
概述
通过IO引脚输出高低电平控制风扇转动。高电平转动,低电平则否。
技术参数
- 工作电压:VCC 3.3-5V
- 模块尺寸:24x46x7.5mm
引脚定义
VCC | 电源 |
NC | 空脚 |
DI | 数字输入(高低电平控制风扇) |
GND | 地 |
使用教程
Arduino示例
//程序功能:按键按下,风扇转动;按键松开,风扇停止// int buttonPin =2; int fanPin=3; int val; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(buttonPin,INPUT); pinMode(fanPin,OUTPUT); } void loop() { val=digitalRead(buttonPin); Serial.print(val); if(val==HIGH) { digitalWrite(fanPin,HIGH); } else { digitalWrite(fanPin,LOW); } }
MicroPython示例
//程序功能:如果按键按下打开排风扇,否则关闭// from microbit import * def digitalRead(pin): pin.read_digital() pin.set_pull(pin.NO_PULL) return pin.read_digital() while True: if digitalRead(pin2): pin0.write_digital(1) sleep(1000) else: pin0.write_digital(0)
图形化示例
版本历史记录
Version | Date | Note [+]新增[-]删除[^]修复 |
---|---|---|
V2.0 |