Arduino读取写入电压值

读取写入方式分为数字和模拟

读取方式:(注意接地)

数字:digitalRead(pin);
 

模拟:
analogRead(A1);
float val=value*(5.0/1023.0);                  //  0·····1023

写入方式:

数字:digitalWrite(pin,HIGH/LOW);

模拟:analogWrite(pwm,0·255);   //  这里涉及脉冲宽度调制,与占空比方波有关,如果要去读取对应pin值推荐用万用表,如果利用digitalRead(pin);会得到不稳定的0或者1,数量取决于0---255这个数字

例如:

 analogWrite(3,128);

 value=digitalRead(5);

原文地址:https://www.cnblogs.com/MCSFX/p/11506166.html