pin参数表示要配置的引脚,mode参数表示设置的参数INPUT(输入)和OUTPUT(输出)。INPUT参数用于读取信号,OUTPUT用于输出控制信号。PIN的范围是数字引脚0-13,也可以把模拟引脚(A0-A5)作为数字引脚使用,此时编号为14脚对应模拟引脚0,19引脚对应模拟引脚5,。一般会放在setup里,先设置再使用。 digitalWrite(pin,value); 该函...
*/charorder= "" ;//定义order变量intpin =3;voidsetup() {Serial.begin(9600); pinMode(pin,OUTPUT); }voidloop() {if(Serial.available() >0){order=Serial.read();Serial.println(order);//串口打印输出变量orderif(order==('o')) {Serial.println("open"); digitalWrite(pin,HIGH); }elseif(o...
ReadAnalogVoltage Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor. Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu). Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V...
循环功能:传感器值由analogRead()函数读取并显示在串行监视器上 sensorValue = analogRead(MQ2pin);//read analog input pin 0Serial.print("Sensor Value:"); Serial.print(sensorValue); 当气体浓度足够高时,传感器通常会输出大于300的值。我们可以使用if语句监控此值。当传感器值超过300时,我们将显示“检测到烟雾!
// make the button‘s pin an input: pinMode(button, INPUT); // to print first value of count_presses which is 0 Serial.println(count_presses); } void loop() { // read the button input pin: int button_state = digitalRead(button); ...
pin:要设置其模式的引脚编号 mode:INPUT(输入模式),OUTPUT(输出模式),INPUT_PULLUP(上拉输入模式) 返回值:无 digitalRead(): 描述:读取指定数字引脚的值 函数原型:digitalRead(pin) 参数:要读取的数字引脚的编号 返回值:HIGH(1),LOW(0) digitalWrite(): 描述:将数字 HIGH 或 LOW 的值写入数字引脚 函数原...
pinMode(pushButton, INPUT); } // the loop routine runs over and over again forever: void loop() { // read the input pin: int buttonState = digitalRead(pushButton); // print out the state of the button: Serial.println(buttonState); ...
unsigned char PS2::read(void){unsigned char data = 0x00;unsigned char i;unsigned char bit = 0x01;pinMode(_ps2clk, INPUT);digitalWrite(_ps2clk, HIGH);pinMode(_ps2data, INPUT);digitalWrite(_ps2data, HIGH); //以上把时钟和数据均设置为高位,开始接受输入delayMicroseconds(50);while (digitalRead...
(9600);pinMode(2,INPUT);pinMode(3,INPUT);}voidloop(){while(Serial.available()>0)//不断检测串口是否有数据{receive_data();//接受串口数据test_do_data();//测试数据是否正确并更新标志位}}voidreceive_data(void){int i;for(i=0;i<3;i++){comdata[i]=Serial.read();//延时一会,让串口...
pinMode(ch5,INPUT); //配置引脚5为输入 pinMode(ch6,INPUT); //配置引脚5为输入 sg3.attach(9); //定义舵机3输出引脚 sg2.attach(10); //定义舵机2输出引脚 } void loop() { Serial.print(pulseIn(ch5,HIGH));//以十进制形式输出()的ASCII编码值,并同时跟随一个回车和换行符,pulseIn()函数用来...