数字信号、模拟信号操作函数
数字信号、模拟信号操作函数
数字信号操作函数
- pinMode(pin,mode)
功能:
设置指定引脚工作模式
参数:
pin 为数字引脚 0~13 、A0~A5
mode 为INPUT/OUTPUT/INPUT_PULLUP
返回值 无
2.digitalRead(pin)
int dwq=A0;//电位器A0
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(dwq,INPUT);//引脚工作模式为输入
}
void loop() {
// put your main code here, to run repeatedly:
int dwqRead=digitalRead(dwq);//读取电位器的值
Serial.println(dwqRead);//输出电位器的值 在0~127 为0 ,128~255 为1
delay(1000);
}
功能
从指定数字引脚读取值
参数:
pin 数字引脚0~13 、A0~A5
返回值 1 --HIGH 2 -- LOW
3.digitalWrite(pin,value)
功能
向指定的数字引脚下入 1 --HIGH 、0 -- LOW
参数
pin 数字引脚0~13 、A0~A5
value 为 1 --HIGH 或 0 -- LOW
模拟信号操作函数
- analogRead(pin) 输入 A0~A5口
功能 从指定的模拟引脚读取值
参数 pin为模拟引脚 A0~A5
返回值 0~1023
- analogWrite(pin,write) 输出 PWM口
功能
向指定的模拟引脚写入值
参数
pin 为引脚 3 5 6 9 10 11
value 为0~255
返回值
无
作者:newcode 更多资源请关注纽扣编程微信公众号

从事机器人比赛、机器人等级考试、少儿scratch编程、信息学奥赛等研究学习

浙公网安备 33010602011771号