Arduino基础学习总结

arduino设计

基本指令篇
---数字输入输出接口
digitalRead(pin);//读值
digitalWrite(pin,HIGH);//写高或低
pinMode(pin,) //工作模式设置INPUT, OUTPUT, or INPUT_PULLUP上拉输入

---模拟输入输出
analogRead() 读入模拟电压返回0-1023
analogReference();//参量配置INTERNAL、INTERNAL1V1、INTERNAL2V56
analogWrite(pin,value);//输出多大占空比

---Advanced I/O接口
pulseIn(pin, value, timeout);//返回PIN引脚的高电平或低电平脉冲,timeout为时间限制。

---Math部分
map();
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}类似于分辨率的放大缩小
constrain(x,a,b)//限制
abs;//绝对值
max,min;/最大最小值
sq(x);//x的平方
sqrt(x);//x的平方根

---时间模块
delay(ms);//延时模块;
delayMicrosecond(us);//微秒级
millis();//返回显示运行时间
micros();//返回显示当前运行微秒级时间


【库文件】
1、Servo类  伺服
The angle of the servo, from 0 to 180 degrees.
serve.attach();//绑定引脚
servo.read();//读角度
servo.write(angle) //写角度
writeMicroseconds()精确控制到us
serve.detach();//释放引脚

舵机是以PWM周期进行控制的。
1500脉冲代表中值   90度
1000    0度
2000    180度

2、Serial串口
Serial.begin(波特率);//开启传输

(1)打印数据
Serial.print("  ");//打印
Serial.print(变量);//打印变量
(2)接收数据
SoftwareSerial: available();接收到的字节数量
需要先判断是否有接收数据,
Serial.read();//接收数据


【中断】

attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
//中断;三个参量;
中断引脚(数字引脚转为中断标)
中断函数(随意函数名)
中断源方式(上升沿RISING;下降沿FALLING;低电平LOW,高电平HIGH)

原文地址:https://www.cnblogs.com/flyingjun/p/8677652.html