#include<Arduino.h>intled=LED_BUILTIN;//在RPI Pico中 LED_BUILTIN=25intbtn=1;voidsetup(){// put your setup code here, to run once:pinMode(led,OUTPUT);pinMode(btn,INPUT_PULLUP);//配置为上拉输入}voidloop(){digitalWrite(led,digitalRead(btn));} 因为BTN引脚为上拉输入,按键没有按下时读...
intMODE_BUTTON =6;41intmode =0;//0: 关机; 1: 长亮; 2: blink42boolean lastButton_mode =LOW;43boolean currentButton_mode =LOW;4445voidsetup()46{47pinMode(BLED, OUTPUT);48pinMode(GLED, OUTPUT);49pinMode(RLED, OUTPUT);50pinMode(R_BUTTON, INPUT);51pinMode(G_BUTTON, INPUT);52pinMo...
https://www.arduino.cc/en/Tutorial/BuiltInExamples/InputPullupSerial */ void setup() { //start serial connection Serial.begin(9600); //configure pin 2 as an input and enable the internal pull-up resistor pinMode(2, INPUT_PULLUP); pinMode(13, OUTPUT); } void loop() { //read the ...
当使用INPUT_PULLUP模式时,引脚作为数字输入,且使能内部上拉电阻。13号引脚不建议作为数字输入引脚使用。因为13脚默认连接了一个板载的LED灯,即便是你使能了上拉电阻,LED的电阻会拉低电压,使得引脚依然是低电平。如果你非要使用13作为输入,那就外置拉电阻。 当使用OUTPUT模式时,引脚作为数字输出,引脚表现为低阻抗,...
This example code is in the public domain */ void setup() { //start serial connection Serial.begin(9600); //configure pin2 as an input and enable the internal pull-up resistor pinMode(2, INPUT_PULLUP); pinMode(13, OUTPUT); }
This article describes my version of digital input/output functions for Arduino, which work faster than the 'built-in' functions while remaining as easy to use and portable as the original ones. If you just want to try the new functions, feel free to go directly to "Usin...
int ledPin = 9; //LED 接数字引脚 9int buttonPin = 2; //按键接中断 0,即数字引脚 2void setup() {pinMode(ledPin, OUTPUT);pinMode(buttonPin,INPUT_PULLUP); //按键设为输入模式,内部上拉attachInterrupt(0, testProgram, FALLING); //下降沿触发中断 0,调用 testProgram 函数}void loop(){ ...
(p){pinMode(pin,OUTPUT);digitalWrite(pin,state);}LED::~LED(){disattach();}voidLED::on(){digitalWrite(pin,HIGH);}voidLED::off(){digitalWrite(pin,LOW);}boolLED::getState(){returndigitalRead(pin);}voidLED::disattach()//引脚回收,恢复到上电状态{digitalWrite(pin,LOW);pinMode(pin,INPUT)...
//AirLink modebreak;default:break;}}voidsetup(){// put your setup code here, to run once:Serial.begin(9600);pinMode(ledPin,OUTPUT);// sets the digital pin as outputpinMode(myledPin,OUTPUT);// sets the digital pin as outputpinMode(KEY1,INPUT_PULLUP);pinMode(KEY2,INPUT_PULLUP);my...
pinMode( LED_RED3_PIN, OUTPUT ); pinMode( LED_GREEN_PIN, OUTPUT ); pinMode( SW_PIN, INPUT_PULLUP ); digitalWrite( LED_RED1_PIN, LOW); digitalWrite( LED_RED2_PIN, LOW); digitalWrite( LED_RED3_PIN, LOW); digitalWrite( LED_GREEN_PIN, LOW); ...