fixed conflicts
This commit is contained in:
73
src/main.cpp
73
src/main.cpp
@@ -1,6 +1,5 @@
|
|||||||
#include <Tone32.h>
|
#include <Tone32.h>
|
||||||
#include <NeoPixelBus.h>
|
#include <NeoPixelBus.h>
|
||||||
#include "Button2.h"
|
|
||||||
|
|
||||||
#define BUZZER_PIN 5
|
#define BUZZER_PIN 5
|
||||||
#define BUZZER_CHANNEL 0
|
#define BUZZER_CHANNEL 0
|
||||||
@@ -10,6 +9,7 @@ const uint8_t DotDataPin = 14;
|
|||||||
|
|
||||||
#define colorSaturation 128
|
#define colorSaturation 128
|
||||||
#define MAX_ITER 2000000
|
#define MAX_ITER 2000000
|
||||||
|
#define IMPULS 400 //400 ms impuls minimal
|
||||||
// for software bit bang
|
// for software bit bang
|
||||||
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, DotDataPin);
|
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, DotDataPin);
|
||||||
// for hardware SPI (best performance but must use hardware pins)
|
// for hardware SPI (best performance but must use hardware pins)
|
||||||
@@ -58,19 +58,17 @@ static RgbColor LEDoffColor;
|
|||||||
|
|
||||||
RgbColor rgbArray[] = {red, blue, green, white};
|
RgbColor rgbArray[] = {red, blue, green, white};
|
||||||
|
|
||||||
#define BELL_PIN 12 // Pin 12 as default
|
|
||||||
#define MINIMAL_GAP 30*1000 // 30 seconds between rings
|
|
||||||
#define IMPULS 500 // minimal press of button
|
|
||||||
|
|
||||||
const byte interruptPin = 17;
|
const byte interruptPin = 17;
|
||||||
|
volatile int interruptCounter = 0;
|
||||||
|
int numberOfInterrupts = 0;
|
||||||
|
|
||||||
unsigned long last_low = 0; // time of uptime
|
unsigned long one,zero;
|
||||||
unsigned long last_high = 0;
|
|
||||||
unsigned long last_sended = 0;
|
|
||||||
bool run;
|
bool run;
|
||||||
|
|
||||||
TaskHandle_t Task1;
|
TaskHandle_t Task1;
|
||||||
Button2 buttonBELL = Button2(17,INPUT_PULLDOWN,false,100U);
|
|
||||||
|
|
||||||
|
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
||||||
|
|
||||||
void LCD_snake()
|
void LCD_snake()
|
||||||
{
|
{
|
||||||
@@ -103,6 +101,7 @@ void LCD_blink_color()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void beep(void * pvParameters) {
|
void beep(void * pvParameters) {
|
||||||
|
Serial.println("Piezo core 2...");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (run) {
|
if (run) {
|
||||||
tone(BUZZER_PIN, NOTE_C4, 500, BUZZER_CHANNEL);
|
tone(BUZZER_PIN, NOTE_C4, 500, BUZZER_CHANNEL);
|
||||||
@@ -125,31 +124,15 @@ void beep(void * pvParameters) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void change(Button2& btn) {
|
void IRAM_ATTR handleInterrupt() {
|
||||||
Serial.println("CHANGE");
|
|
||||||
if (btn.isPressed()) {
|
|
||||||
unsigned long pressed = millis() - last_high;
|
|
||||||
|
|
||||||
if (last_high == 0) return;
|
portENTER_CRITICAL_ISR(&mux);
|
||||||
|
|
||||||
Serial.print("released: ");
|
if (digitalRead(interruptPin) == HIGH) zero = millis();
|
||||||
Serial.println(pressed);
|
if (digitalRead(interruptPin) == LOW) one = millis();
|
||||||
|
|
||||||
if (pressed < IMPULS) {
|
interruptCounter++;
|
||||||
Serial.println("Interval too low");
|
portEXIT_CRITICAL_ISR(&mux);
|
||||||
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() {
|
void setup() {
|
||||||
@@ -161,8 +144,11 @@ void setup() {
|
|||||||
strip.ClearTo(black);
|
strip.ClearTo(black);
|
||||||
strip.Show();
|
strip.Show();
|
||||||
|
|
||||||
Serial.println("Monitoring:");
|
one = zero = millis();
|
||||||
buttonBELL.setChangedHandler(change);
|
|
||||||
|
Serial.println("Monitoring interrupts: ");
|
||||||
|
pinMode(interruptPin, INPUT_PULLUP);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, CHANGE);
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(
|
xTaskCreatePinnedToCore(
|
||||||
beep, /* Task function. */
|
beep, /* Task function. */
|
||||||
@@ -177,7 +163,24 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
buttonBELL.loop();
|
if(interruptCounter>0){
|
||||||
|
|
||||||
if (run) LCD_snake();
|
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;
|
||||||
|
zero = one = 0;
|
||||||
|
}
|
||||||
|
else run = false;
|
||||||
|
|
||||||
|
if (run) LCD_snake();
|
||||||
|
|
||||||
|
}
|
||||||
|
delay(100);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user