5134| 2
|
想用人体红外传感器控制舵机来回180度旋转来这,不知道..... |
#include <Servo.h> Servo myservo; //声明舵机 int sensorPin =2; //传感器连接到数字2 int pos = 0; //储存舵机状态 int sensorState =0; //变量sensorState用于存储传感器状态 void setup() { Serial.begin(9600); myservo.attach(9); //连接9号口 pinMode(sensorPin, INPUT); //传感器为输入设备 } void loop(){ sensorState =digitalRead(sensorPin); //读取传感器的值 if ( sensorState== HIGH) { //如果为高 pos=0; } if ( sensorState== LOW) { //如果为低 pos=180; } } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed