Arduino 使用单发而不是按钮

Arduino 使用单发而不是按钮,arduino,Arduino,如果按下一个按钮,我会尝试在一定时间内创建一个单脉冲,而不必按住按钮等待所需的时间。这是我的代码(不要担心读取2,我需要稍后将其重命名为其他变量) 我建议在你的电路中加一个单稳态多谐振荡器。 这里解释了单稳态多谐振荡器的工作原理 我建议在你的电路中增加一个单稳态多谐振荡器。 这里解释了单稳态多谐振荡器的工作原理 你的问题是什么?我是Arduino和wan的新手,我不知道如何创建一个功能?我是否可以只按一个按钮在一定时间内发送高输入?你的问题是什么?我是Arduino和wan的新手,如何创建一个功

如果按下一个按钮,我会尝试在一定时间内创建一个单脉冲,而不必按住按钮等待所需的时间。这是我的代码(不要担心读取2,我需要稍后将其重命名为其他变量)


我建议在你的电路中加一个单稳态多谐振荡器。
这里解释了单稳态多谐振荡器的工作原理

我建议在你的电路中增加一个单稳态多谐振荡器。
这里解释了单稳态多谐振荡器的工作原理

你的问题是什么?我是Arduino和wan的新手,我不知道如何创建一个功能?我是否可以只按一个按钮在一定时间内发送高输入?你的问题是什么?我是Arduino和wan的新手,如何创建一个功能?我是否可以只按一个按钮在一定时间内发送高输入
const int buttonPin = 10;    // the number of the pushbutton pin
const int ledPin1 = 11;      // the number of the LED pin
const int ledPin2 = 12; 

// Variables will change:
int ledState1 = LOW;         // the current state of the output pin
int ledState2 = LOW; 
int buttonState;             // the current reading from the input pin
int lastButtonState = HIGH;   // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime1 = 0;  // the last time the output pin was toggled
long debounceDelay1 = 0;    // the debounce time; increase if the output flickers
long lastDebounceTime2 = 0;  // the last time the output pin was toggled
long debounceDelay2 = 300;

void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);

// set initial LED state
digitalWrite(ledPin1, ledState1);
digitalWrite(ledPin2, ledState2);
}

void loop() {

int reading2 = digitalRead(buttonPin);

if (reading2 == HIGH){
ledState1 = !ledState1;
digitalWrite(ledPin1, ledState1);
}
else if(ledState2 == LOW){
ledState1 = LOW;
digitalWrite(ledPin1, ledState1);
}
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH),  and you've waited
// long enough since the last press to ignore any noise:

// If the switch changed, due to noise or pressing:
if (reading2 != lastButtonState) {
// reset the debouncing timer
lastDebounceTime2 = millis();
}

if ((millis() - lastDebounceTime2) > debounceDelay2) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:

// if the button state has changed:
if (reading2 != buttonState) {
  buttonState = reading2;

  // only toggle the LED if the new button state is HIGH
  if (buttonState == HIGH) {
    ledState2 = !ledState2;
  }
  }
  }

   // set the LED:
   digitalWrite(ledPin2, ledState2);


   lastButtonState = reading2;