// initialize the pushbutton pin as an input: 初始化按钮开关为输入 pinMode(buttonPin, INPUT); } (4)循环函数 void loop() { // read the state of the pushbutton value: 读取按钮开关的状态值 buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. If it is, the b...
// button's pressed, and off when it's not: if (sensorVal == HIGH) { digitalWrite(13, LOW); } else { digitalWrite(13, HIGH); } } (2)注释 /* Input Pull-up Serial 输入上拉串口 This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a digital input on pin 2 and...
pinMode(ledPin,OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin,INPUT); } voidloop() { // read the state of the pushbutton value: buttonState=digitalRead(buttonPin); // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if(buttonState=...
This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Button */// constants won't change. They're used here to set pin numbers:constintbuttonPin=2;// the number of the pushbutton pinconstintledPin=13;// the number of the LED pin// variables will change:int...
(9600);// make the pushbutton's pin an input:pinMode(pushButton,INPUT);}// the loop routine runs over and over again forever:voidloop(){// 读取pin2脚电平状态intbuttonState=digitalRead(pushButton);// 输出电平的状态值Serial.println(buttonState);delay(1000);// 原例程延时1ms,建议加大延时,...
variable of theintegerdatatype. The first step to reading an Arduino button state is to choose which pin we will connect the button to. For this example, we will use pin 11. Since a button is an input device, we need to declare its pin as an input (do this in the setup function)...
//configure pin2 as an input and enable the internal pull-up resistor pinMode(2, INPUT_PULLUP); pinMode(13, OUTPUT); } void loop() { //read the pushbutton value into a variable int sensorVal = digitalRead(2); //print out the value of the pushbutton ...
This example code is in the public domain.http://www.arduino.cc/en/Tutorial/Button*/intbuttonState =0;voidsetup() { pinMode(2, INPUT); pinMode(13, OUTPUT); }voidloop() {//read the state of the pushbutton valuebuttonState = digitalRead(2);//check if pushbutton is pressed. if it...
On Windows, you can test that the sketch is working properly by opening up the joystick control panel (joy.cpl) or by usingHTML5 Gamepad Tester. If you uploaded the XInput 'Blink' example, the #1 button ('A') should be slowly turning on and off. ...
//configure pin2 as an input and enable the internal pull-up resistor pinMode(2, INPUT_PULLUP); pinMode(13, OUTPUT); } void loop() { //read the pushbutton value into a variable int sensorVal = digitalRead(2); //print out the value of the pushbutton ...