// checking the modulo of the button push counter. // the modulo function gives you the remainder of // the division of two numbers: if (buttonPushCounter % 4 == 0) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } } [Get Code] 更多 pinMode() digitalWrite() ...
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=...
const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin 按钮和 LED 针脚编号 // Variables will change: 变量会被修改 int ledState = HIGH; // the current state of the output pin int buttonState; // the current reading fro...
buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } } [Get Code] 更多 pinMode() ...
[Get Code] 更多 setup() loop() pinMode() digitalRead() delay() int serial DigitalPins Blink Without Delay: 不用delay()函数,使LED灯闪烁 Button: 用一个按钮来控制LED灯 Debounce: 读取一个按钮,并滤掉噪音 Button State Change: 记录按键按下的次数 ...
// put your setup code here, to run once: pinMode(ledpin, OUTPUT);//设置led连接引脚为输出模式 pinMode(buttonpin, INPUT); //设置button连接引脚为输入模式 } void loop() { // 检测按钮是否被按下 repeatedly: boolean buttonstate = digitalRead(buttonpin); ...
const int buttonpin = 2;//button连接引脚 const int ledpin = 13;//led连接引脚 void setup() { // put your setup code here, to run once: pinMode(ledpin, OUTPUT);//设置led连接引脚为输出模式 pinMode(buttonpin, INPUT); //设置button连接引脚为输入模式 ...
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:intbutton...
(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,建议加大延时,...
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...