button2
This commit is contained in:
@@ -14,7 +14,7 @@ board = az-delivery-devkit-v4
|
||||
framework = arduino
|
||||
monitor_port = COM[13]
|
||||
monitor_speed = 115200
|
||||
|
||||
lib_deps =
|
||||
evert-arias/EasyBuzzer@^1.0.4
|
||||
lbernstone/Tone32@^1.0.0
|
||||
lennarthennigs/Button2@^1.2.0
|
||||
|
||||
71
src/main.cpp
71
src/main.cpp
@@ -1,5 +1,6 @@
|
||||
#include <Tone32.h>
|
||||
#include <NeoPixelBus.h>
|
||||
#include "Button2.h"
|
||||
|
||||
#define BUZZER_PIN 5
|
||||
#define BUZZER_CHANNEL 0
|
||||
@@ -9,7 +10,6 @@ const uint8_t DotDataPin = 14;
|
||||
|
||||
#define colorSaturation 128
|
||||
#define MAX_ITER 2000000
|
||||
#define IMPULS 400 //400 ms impuls minimal
|
||||
// for software bit bang
|
||||
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, DotDataPin);
|
||||
// for hardware SPI (best performance but must use hardware pins)
|
||||
@@ -58,17 +58,19 @@ static RgbColor LEDoffColor;
|
||||
|
||||
RgbColor rgbArray[] = {red, blue, green, white};
|
||||
|
||||
const byte interruptPin = 17;
|
||||
volatile int interruptCounter = 0;
|
||||
int numberOfInterrupts = 0;
|
||||
#define BELL_PIN 12 // Pin 12 as default
|
||||
#define MINIMAL_GAP 30*1000 // 30 seconds between rings
|
||||
#define IMPULS 500 // minimal press of button
|
||||
|
||||
unsigned long one,zero;
|
||||
const byte interruptPin = 17;
|
||||
|
||||
unsigned long last_low = 0; // time of uptime
|
||||
unsigned long last_high = 0;
|
||||
unsigned long last_sended = 0;
|
||||
bool run;
|
||||
|
||||
TaskHandle_t Task1;
|
||||
|
||||
|
||||
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
||||
Button2 buttonBELL = Button2(17,INPUT_PULLDOWN,false,100U);
|
||||
|
||||
void LCD_snake()
|
||||
{
|
||||
@@ -123,15 +125,31 @@ void beep(void * pvParameters) {
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR handleInterrupt() {
|
||||
void change(Button2& btn) {
|
||||
Serial.println("CHANGE");
|
||||
if (btn.isPressed()) {
|
||||
unsigned long pressed = millis() - last_high;
|
||||
|
||||
portENTER_CRITICAL_ISR(&mux);
|
||||
if (last_high == 0) return;
|
||||
|
||||
if (digitalRead(interruptPin) == HIGH) one = millis();
|
||||
if (digitalRead(interruptPin) == LOW) zero = millis();
|
||||
Serial.print("released: ");
|
||||
Serial.println(pressed);
|
||||
|
||||
interruptCounter++;
|
||||
portEXIT_CRITICAL_ISR(&mux);
|
||||
if (pressed < IMPULS) {
|
||||
Serial.println("Interval too low");
|
||||
return;
|
||||
}
|
||||
|
||||
if (millis() - last_sended < MINIMAL_GAP) {
|
||||
Serial.println("Minimal gap not meeted");
|
||||
return;
|
||||
}
|
||||
|
||||
run = true;
|
||||
last_sended = millis();
|
||||
} else {
|
||||
last_high = millis();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
@@ -143,11 +161,8 @@ void setup() {
|
||||
strip.ClearTo(black);
|
||||
strip.Show();
|
||||
|
||||
one = zero = millis();
|
||||
|
||||
Serial.println("Monitoring interrupts: ");
|
||||
pinMode(interruptPin, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, CHANGE);
|
||||
Serial.println("Monitoring:");
|
||||
buttonBELL.setChangedHandler(change);
|
||||
|
||||
xTaskCreatePinnedToCore(
|
||||
beep, /* Task function. */
|
||||
@@ -162,21 +177,7 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
|
||||
if(interruptCounter>0){
|
||||
buttonBELL.loop();
|
||||
|
||||
portENTER_CRITICAL(&mux);
|
||||
interruptCounter--;
|
||||
portEXIT_CRITICAL(&mux);
|
||||
|
||||
numberOfInterrupts++;
|
||||
Serial.print("An interrupt has occurred. Total: ");
|
||||
Serial.println(numberOfInterrupts);
|
||||
|
||||
if (zero > one && zero - one > IMPULS) run = true;
|
||||
else run = false;
|
||||
|
||||
if (run) LCD_snake();
|
||||
|
||||
}
|
||||
delay(100);
|
||||
if (run) LCD_snake();
|
||||
}
|
||||
Reference in New Issue
Block a user