volatile int32_t count = 0;
volatile uint32_t buttonCount1 = 0;
volatile uint32_t buttonCount2 = 0;
void incrementCount() {
count++;
buttonCount1++;
}
void decrementCount() {
count--;
buttonCount2++;
}
void setup() {
Serial.begin(115200);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), incrementCount, RISING);
attachInterrupt(digitalPinToInterrupt(3), decrementCount, RISING);
}
void loop() {
Serial.print("Лічильник: ");
Serial.println(count);
if(buttonCount1 % 10 == 0)
{
Serial.print("Натискань кнопки 1: ");
Serial.println(buttonCount1);
}
if(buttonCount2 % 10 == 0)
{
Serial.print("Натискань кнопки 2: ");
Serial.println(buttonCount2);
}
delay(100);
}
Loading
st-nucleo-l031k6
st-nucleo-l031k6