Arduino教程(5)马达和三极管(晶体管)


http://www.guanlantech.com/2014/05/arduino-tutorial5/

//Program by Jeremy Blum
//www.jeremyblum.com 根据IR距离传感器的数据控制伺服马达
//Controls a Servo Motor using the info from an IR Distance Sensor

//Include Servo Library
#incl...详情
http://www.guanlantech.com/2014/05/arduino-tutorial5/

//Program by Jeremy Blum
//www.jeremyblum.com 根据IR距离传感器的数据控制伺服马达
//Controls a Servo Motor using the info from an IR Distance Sensor

//Include Servo Library
#include <Servo.h> 导入Servo库,include含义是包括

//Define Pins
int servoPin = 9; 伺服马达接引脚9
int distPin = 0; 传感器接模拟引脚0

//Create Servo Object
Servo jeremysServo; 创建一个类型为Servo名叫jeremysServo的对象

void setup()
{

//Attaches the Servo to our object attach含义联接起来
jeremysServo.attach(servoPin); 将对象jeremysServo和引脚9连接起来
}

void loop()
{
//Read the Distance Sensor and adjust values
int dist = analogRead(distPin); 传感器读入的数据在0-1013之间
int pos = map(dist, 0, 1023, 0, 180); 将其和0-180之间的数对应起来

//Turn the servo
jeremysServo.write(pos); 转动伺服马达

}隐藏

标签: arduino视频