This commit is contained in:
2020-10-15 14:05:49 +02:00
commit d2b605289d
7 changed files with 310 additions and 0 deletions

182
src/main.cpp Normal file
View File

@@ -0,0 +1,182 @@
#include <Tone32.h>
#include <NeoPixelBus.h>
#define BUZZER_PIN 5
#define BUZZER_CHANNEL 0
const uint16_t PixelCount = 10; // this example assumes 4 pixels, making it smaller will cause a failure
// make sure to set this to the correct pins
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)
//NeoPixelBus<DotStarBgrFeature, DotStarSpiMethod> strip(PixelCount);
// DotStars that support RGB color and a overall luminance/brightness value
// NeoPixelBus<DotStarLbgrFeature, DotStarMethod> strip(PixelCount, DotClockPin, DotDataPin);
// DotStars that support RGBW color with a seperate white element
//NeoPixelBus<DotStarWbgrFeature, DotStarMethod> strip(PixelCount, DotClockPin, DotDataPin);
RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation);
RgbColor white(colorSaturation);
RgbColor black(0);
RgbColor Aqua(0,255,255);
RgbColor Black(0,0,0);
RgbColor Blue(0,0,255);
RgbColor Cream(255,251,240);
RgbColor Grey(128,128,128);
RgbColor Fuchsia(255,0,255);
RgbColor Green(0,128,0);
RgbColor Lime_green(0,255,0);
RgbColor Maroon(128,0,0);
RgbColor Navy(0,0,128);
RgbColor Olive_green(128,128,0);
RgbColor Purple(255,0,255);
RgbColor Red(255,0,0);
RgbColor Silver(192,192,192);
RgbColor Teal(0,128,128);
RgbColor White(255,255,255);
RgbColor rgbArrayL[] = {Aqua, Black, Blue, Cream, Grey, Fuchsia, Green, Lime_green,Maroon,Navy, Olive_green,Purple,Red,Silver,Teal,White};
// for use with RGB DotStars when using the luminance/brightness global value
// note that its range is only 0 - 31 (31 is full bright) and
// also note that it is not useful for POV displays as it will cause more flicker
RgbwColor redL(colorSaturation, 0, 0, 31); // use white value to store luminance
RgbwColor greenL(0, colorSaturation, 0, 31); // use white value to store luminance
RgbwColor blueL(0, 0, colorSaturation, 31); // use white value to store luminance
RgbwColor whiteL(255, 255, 255, colorSaturation / 8); // luminance is only 0-31
// Position of snake
static unsigned int n;
static RgbColor LEDonColor;
static RgbColor LEDoffColor;
RgbColor rgbArray[] = {red, blue, green, white};
const byte interruptPin = 17;
volatile int interruptCounter = 0;
int numberOfInterrupts = 0;
unsigned long one,zero;
bool run;
TaskHandle_t Task1;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
void LCD_snake()
{
// set the colors
Serial.println("Snake:");
for (n=0;n<50;n++) {
for (int i=0;i < PixelCount;i++) {
strip.SetPixelColor(i,rgbArrayL[(i + n) % sizeof(rgbArrayL)]);
}
strip.Show();
delay(250);
}
strip.ClearTo(black);
strip.Show();
}
void LCD_blink_color()
{
Serial.print("Blink:");
if (n % 2)
for (int i=0;i < PixelCount;i++) {
strip.SetPixelColor(i,LEDonColor);
} else {
for (int i=0;i < PixelCount;i++) {
strip.SetPixelColor(i,LEDoffColor);
}
}
n++;
strip.Show();
}
void beep(void * pvParameters) {
for (;;) {
if (run) {
tone(BUZZER_PIN, NOTE_C4, 500, BUZZER_CHANNEL);
noTone(BUZZER_PIN, BUZZER_CHANNEL);
tone(BUZZER_PIN, NOTE_D4, 500, BUZZER_CHANNEL);
noTone(BUZZER_PIN, BUZZER_CHANNEL);
tone(BUZZER_PIN, NOTE_E4, 500, BUZZER_CHANNEL);
noTone(BUZZER_PIN, BUZZER_CHANNEL);
tone(BUZZER_PIN, NOTE_F4, 500, BUZZER_CHANNEL);
noTone(BUZZER_PIN, BUZZER_CHANNEL);
tone(BUZZER_PIN, NOTE_G4, 500, BUZZER_CHANNEL);
noTone(BUZZER_PIN, BUZZER_CHANNEL);
tone(BUZZER_PIN, NOTE_A4, 500, BUZZER_CHANNEL);
noTone(BUZZER_PIN, BUZZER_CHANNEL);
tone(BUZZER_PIN, NOTE_B4, 500, BUZZER_CHANNEL);
noTone(BUZZER_PIN, BUZZER_CHANNEL);
run = false;
}
delay(100);
}
}
void IRAM_ATTR handleInterrupt() {
portENTER_CRITICAL_ISR(&mux);
if (digitalRead(interruptPin) == HIGH) one = millis();
if (digitalRead(interruptPin) == LOW) zero = millis();
interruptCounter++;
portEXIT_CRITICAL_ISR(&mux);
}
void setup() {
Serial.begin(115200);
Serial.println("Initializing strip...");
strip.Begin();
strip.ClearTo(black);
strip.Show();
one = zero = millis();
Serial.println("Monitoring interrupts: ");
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, CHANGE);
xTaskCreatePinnedToCore(
beep, /* Task function. */
"Task1", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
}
void loop() {
if(interruptCounter>0){
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);
}