Я пытаюсь создать импульс одного выстрела в течение определенного промежутка времени, если кнопка нажата, вместо того, чтобы удерживать мою кнопку в течение времени, которое требуется, это мой код (не беспокойтесь о reading2 мне нужно будет переименовать ему некоторые другие переменные позже)Использование одного снимка вместо кнопок
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;
В чем проблема? – Ccr
Я новичок в Arduino и wan, чтобы создать функцию, я могу отправить входной максимум в течение определенного времени только с одной кнопки. – ChrisPlusPlus