/*Bugs:
Was man beim Überarbeiten verbessen kann:
Was verbessert werden kann:
-playMelodieForCountDown() Funktion für jede Countdown-Sekunde ein eigenen ton spielen.
Worauf geachtet werden muss:
-Serial.print() und Serial.println() Funktionen sind zu langsam / verlangsamen die ISR,
deshalb nur gezielt dekommentieren um Bugs zu finden
-digitalRead() und digitalWrite() Funktionen sind zu langsam deshalb einfache Auswertung mit
... = (PINX >> ... & 0b00000001) ;
(X hier der PORT) (hier der PORTPIN)
HIGH- Schreiben mit
PORTX |= ( 1 << ..... ) ;
(X hier der PORT) (hier der PORTPIN)
LOW- Schreiben mit
PORTX &= ~( 1 << ..... ) ;
(X hier der PORT) (hier der PORTPIN)
-Man könnte eine eigene Seven Segments Libary schreiben um auch andere Zeichen als Zahlen darzustellen
Noch nicht implementiert:
Erledigt-Setup Firetimer mit einer dynammisch zu ms konfigurierenden Funktion hier
-Abkühlzeit nach dem fire() soll so 3 Sekunden sein
-firetime soll in eeprom gespeichert werden
Verbessert:
ALLE Encoder Inputs laufen auf Interrupts. Gelöst dadurch, dass CLK und Data bei Drücken von SW beide 1 annehmen. Bei diesem Fall wird der Rotationspfad NICHT eingeschlagen sondern der else/bzw. den SW-pressed-Pfad.
Debouncing in der Encoder ISR
*/
// Include library
#include "SevSeg.h"
#define inputFootPaddle 0
#define inputClock 14
#define inputData 15
#define inputSW 16
#define outputRelay 18
#define outputBuzzer 19
//Boolean for LOCK
#define LOCKED 0x1
#define UNLOCKED 0x0
#define PRESSED 0x1
#define UNPRESSED 0x0
#define POSSIBLE 0x1
#define IMPOSSIBLE 0x0
//current displayed value
int currentDiplayValue;
//Limit of FireTime
int fireTimeUpperLimit = 9999;
int fireTimeLowerLimit = 0;
int fireTimeStepSize = 10;
//Value that the encoder is going to be changing
volatile int fireTimeMs = 1000;
volatile int lastFireTime = 0;
//How long the buzzer sounds
unsigned long buzzerTime = 30;
unsigned long buzzerTimeForSelecting = 75;
///////////////////////////////////small delay between the locking inputs needs to be configured!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
unsigned long buzzerTimeForLocking = 550;
//Needed because we use the 16Bit-timer twice for different time spans
int timer10msEnabled = false;
//Needed because the timer is accurat for 10ms but we need to count the interrupts
int maximumCountsOf10ms;
int counterOf10ms = 0;
int lockingFreq = 500;
int unlockingFreq = 200;
int selectingFreq = 130;
int overUnderFlowFreq = 700;
int countDownFreq = 222;
// defaultCDValue:
// 3+1 because wenn the first timerinterrupt happens the value substracted by one before it's first time shown
// e.G. if it was 3 first figure shon is 2 it is shown is
volatile int defaultCDValue = 3 + 1;
//Countdownsecoundsvarible
volatile int countDownSek = defaultCDValue;
//Default Bools
int lockState = UNLOCKED;
int rotationChanges = POSSIBLE;
int countDownTimerEnable = false;
//Delays of Debouncing should be configured according to the sensor debouce specification
unsigned long debounceDelayFP = 50;
unsigned long debounceDelayEncoder = 50; // the debounce time; increase if the output flickers
unsigned long lastInterruptTime = 0; // the last time the Interrupt got called
unsigned long currentTime;
//Needed to see if encoder is moving
volatile int currentStateClock;
volatile int previousStateClock;
volatile int currentStateData;
volatile int previousStateData;
//Needed because the cases in the encoder ISR always catch two states for one step, but we just need one addition/substraction for one step. So we flip a bool to skip one execution
volatile int clockwiseBool = false;
volatile int conterclockwiseBool = false;
volatile int currentStateSW;
volatile int previousStateSW;
volatile int currentFPState = LOW;
volatile int previousFPState = LOW ;
//the rotation direction counterclock- or clock-wise
String encdirection = "";
// Create object
SevSeg sevseg;
// Number of digits in display
byte numberOfDigits = 4;
// Display select pins
byte digitPins[] = {13, 12, 11, 10};
// Display segment pins A,B,C,D,E,F,G,DP
byte segmentPins[] = {9, 2, 3, 5, 6, 8, 7, 4};
// Dropping resistors used
bool resistorsOnSegments = true;
// Decimal Point is used
bool disableDecPoint = false;
//Leading zeros should be displayed
bool leadingZerosIn = false;
//Disable update with Delay
bool updateWithDelaysIn = false;
// Display type
byte hardwareConfig = COMMON_ANODE;
//Brightness
int brightnessOfSevSeg = 90;
void setup16BitTimer1sek() {
//////////Setup 1 secound - countdown-Timer with Compare Output Mode for 16-Bit Timer 1
//Set all Controll-Bits of 16-Bit Timer to 0
TCCR1A = 0;
TCCR1B = 0;
//Set Timer to CTC-Mode (Clear Timer on Compare) WGM10 = 0 ; WGM11 = 0 ; WGM12 = 1
//enough to set WGM01 to 1 because the outher Bits are already set to 0
TCCR1B |= (1 << WGM12);
//Set Preskalar for timer 0
//Calculate preskalar for 1 sek
// Clock source= 16MHz
// Timer-Freq. := 1Hz = 16MHz / Top * pre
// pre = 1024
TCCR1B |= 0b00000101;
//Set OCIE1A to 1 so we enable compare match A
//TIMSK1 |= (1 << OCIE1A);
//--> Top = 16000000/ (1 * 1024) -1 = 15624 //-1 weil 0 nicht als stufe zählt
// TOP = 15624
OCR1A = 15624;
}
void setup16BitTimer10ms() {
//////////Setup 10ms Timer with Compare Output Mode for 16-Bit Timer 1
//Set all Controll-Bits of 16-Bit Timer to 0
TCCR1A = 0;
TCCR1B = 0;
//Set Timer to CTC-Mode (Clear Timer on Compare) WGM10 = 0 ; WGM11 = 0 ; WGM12 = 1
//enough to set WGM01 to 1 because the outher Bits are already set to 0
//Turn on CTC-Mode
TCCR1B |= (1 << WGM12);
//Set Preskalar for timer 0
//Calculate preskalar for 1 sek
// Clock source= 16MHz
// Timer-Freq. := 1Hz = 16MHz / Top * pre
// pre = 256
TCCR1B |= 0b00000100;
//Set enable compare match Interrupt on register OCR1A
//TIMSK1 |= 0b00000010;
//--> Top = 16000000Hz/ (100Hz * 1024) -1 = 624 //-1 weil 0 nicht als stufe zählt
// TOP = 15624
OCR1A = 624;
}
/* not needed for finshed product Xms
void setup8BitTimerms(){
//////////Setup Xms - countdown-Timer with Compare Output Mode for 16-Bit Timer 0
//Set all Controll-Bits of 8-Bit Timer to 0
TCCR2A = 0;
TCCR2B = 0;
//Set Timer to CTC-Mode (Clear Timer on Compare) COM2A0 = 1 ; COM2A1 = 0
TCCR2A |= (1 << COM2A0);
TCCR2A &= ~(1 << COM2A1);
//Set Preskalar for timer 100ms
//Calculate preskalar for 100ms
// Clock source= 16MHz
// Timer-Freq. := 10Hz = 16MHz / (Top * pre ) -1
// Set CS22 = 1 ;CS21 = 1 ; CS20 = 1
// pre = 1024
TCCR2B |= (1<< CS22);
TCCR2B |= (1<< CS21);
TCCR2B |= (1<< CS20);
//--> Top = 16000000/ (10 * 1024) -1 = 15624 //-1 weil 0 nicht als stufe zählt
// TOP = 15624
OCR2A = 15624;
}
*/
/*
void setupADCPinA0(){
ADMUX &= ~(1<<MUX0) | ~(1<<MUX1) | ~(1<<MUX2) | ~(1<<MUX3) //A0 is connected to the ADC
ADMUX |= (1<<REFS0) //Set reference voltage to VCC 5V (REFS0=1)
ADMUX &= ~(1<<REFS1) //(REFS1 = 0)
void setupADCPinA1(){
}
*/
void setupAndStartEncoderInterruptsClock() {
//Setup PinChange Interrupt for
//Interrupts für PORT-PC freischalten:
PCICR |= 0b00000010;
//Interrupts für Pin 14 InputClock in der Maske geöffnet
PCMSK1 |= (1 << 1);
/*
Man benötigt nur einen Pin für den Encoder Interrupt, ansonsten wird die ISR zweimal aufgerufen (einmal zu dec. einmal zu inc.)
//Interrupts für Pin 15 InputData in der Maske geöffnet
PCMSK1 |= (1<<0);
*/
//Serial.println("Encoder Interrupt for Clock/Data Setup complete");
}
void setupAndStartEncoderInterruptsSW() {
//Setup PinChange Interrupt for
//Interrupts für PORT-PC freischalten:
PCICR |= 0b00000010;
//Interrupts für Pin 15 InputSW in der Maske geöffnet
PCMSK1 |= (1 << 2);
//Serial.println("Encoder Interrupt for SW Setup complete");
}
void setupAndStartFootPaddleInterrupt() {
//Interrupts für PORT PD freischalten:
PCICR |= 0b00000100;
//Interrupts für Pin 0 Input in der Maske geöffnet
PCMSK2 |= (1 << 0);
//Serial.println("Footpaddle Interrupt Setup complete");
}
//Zurzeit nur Töne, können aber auch zu Melodien gemacht werden
void playMelodieForLocking() {
tone(outputBuzzer, lockingFreq, buzzerTimeForLocking);
}
void playMelodieForUnlocking() {
tone(outputBuzzer, unlockingFreq, buzzerTimeForLocking);
}
void playMelodieForSelecting() {
tone(outputBuzzer, selectingFreq, buzzerTimeForSelecting);
}
void playMelodieForOverUnderFlow() {
tone(outputBuzzer, overUnderFlowFreq, buzzerTimeForSelecting);
}
void playMelodieForCountDown() {
/*
if (countDownSek == 3){
}
if (countDownSek == 2{
}
if (countDownSek == 1){
}
*/
tone(outputBuzzer, countDownFreq, buzzerTimeForSelecting);
}
void setup() {
// Start display object
sevseg.begin(hardwareConfig, numberOfDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelaysIn, leadingZerosIn, disableDecPoint);
// Set brightness
sevseg.setBrightness(brightnessOfSevSeg);
/*
Electronoobs explanation:
Set encoder pins as inputs with pullups. If!! you use the Encoder MODULE!!, you don't need
pullups for Clock and Data, only for the push button.
*/
//Set all Input Pins to Pullup
//Setup the Footpaddletrigger as normal input
pinMode(inputFootPaddle, INPUT_PULLUP);
//We can set all Input Pins just to INPUT, but the we need a 5V-line(not always given for the encodertype)
pinMode(inputClock, INPUT_PULLUP);
pinMode(inputData, INPUT_PULLUP);
pinMode(inputSW, INPUT_PULLUP);
pinMode(outputRelay, OUTPUT);
pinMode(outputBuzzer, OUTPUT);
//to monitor
//Serial.begin(9600);
setupAndStartEncoderInterruptsClock();
//setupAndStartEncoderInterruptsSW();
//Setup fireTimeMs-Timer
setup16BitTimer1sek();
//Read the initial state of inputClock
//Assign to variable
previousStateClock = (PINC >> 0 & 0b00000001 );
previousStateData = (PINC >> 1 & 0b00000001 );
//Serial.println("Setup Complete");
}
void loop() {
if (lockState == UNLOCKED) {
//Enable state changes in Rotation-Interrupts
rotationChanges = POSSIBLE;
countDownTimerEnable = false;
countDownSek = defaultCDValue;
//Dispaly the begining number of fireTimeMs in Sek with
sevseg.setNumber(fireTimeMs,3);
}
if (lockState == LOCKED) {
if (countDownTimerEnable == true) {
//sevseg.begin(hardwareConfig, numberOfDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelaysIn, false, false);
if (countDownSek != defaultCDValue) { //We don't need to check if countDownSek is different to lastCountDownSek because we should change display as soon as it's possible
//currentDiplayValue = countDownSek;
//Set 7Seg-Display to currentDiplayValue
sevseg.setNumber(countDownSek);
}
}
else {
//Serial.println("Locked!");
rotationChanges = IMPOSSIBLE;
//Set 7Seg-Display to "LOCK"
sevseg.setChars("LOCK");
}
}
// Refresh the display
sevseg.refreshDisplay();
}
ISR(PCINT1_vect) {
currentStateClock = (PINC >> 0 & 0b00000001 );
currentStateData = (PINC >> 1 & 0b00000001 );
currentStateSW = (PINC >> 2 & 0b00000001 );
cli();
unsigned long currentTime = millis();
if ( ( currentTime - lastInterruptTime) > debounceDelayEncoder ) {
Serial.print(previousStateClock);
Serial.print(currentStateClock);
Serial.print(previousStateData);
Serial.print(currentStateData);
Serial.print(previousStateSW);
Serial.print(currentStateSW);
Serial.print(" | ");
if ( ( ( currentStateClock == currentStateData ) && (previousStateClock == previousStateData ) ) || ( currentStateClock == LOW && previousStateClock == LOW && ( currentStateData != previousStateData ) ) ) {
if ( clockwiseBool == true ){
clockwiseBool = !clockwiseBool;
//conterclockwiseBool = false;
//Serial.println("");
//Serial.println("----------------------------");
fireTimeMs += fireTimeStepSize;
tone(outputBuzzer, selectingFreq, buzzerTimeForSelecting);
//Serial.print(previousStateClock);
//Serial.print(currentStateClock);
//Serial.print(previousStateData);
//Serial.print(currentStateData);
//Serial.print(previousStateSW);
//Serial.print(currentStateSW);
Serial.println(" clockwise ");
Serial.println("----------------------------");
if (fireTimeMs > fireTimeUpperLimit ) {
fireTimeMs = fireTimeUpperLimit;
playMelodieForOverUnderFlow();
}
}
else {
clockwiseBool = !clockwiseBool;
}
previousStateClock = currentStateClock;
previousStateData = currentStateData;
previousStateSW = currentStateSW;
}
else if ( ( ( currentStateData == previousStateData ) && (currentStateClock != previousStateClock ) ) || ( currentStateData != previousStateData && currentStateData == previousStateClock && previousStateData == currentStateClock ) ){
if ( conterclockwiseBool == true) {
conterclockwiseBool = !conterclockwiseBool;
//clockwiseBool = false;
//Serial.println("");
//Serial.println("----------------------------");
///*if ( ((currentStateData == HIGH && previousStateData == HIGH )*/ /*|| currentStateData != previousStateData */ ///*) */ && /*(currentStateClock == LOW && previousStateClock == LOW) ||*/ ///* currentStateClock != previousStateClock ) */{
fireTimeMs -= fireTimeStepSize;
tone(outputBuzzer, selectingFreq, buzzerTimeForSelecting);
//Serial.print(previousStateClock);
//Serial.print(currentStateClock);
//Serial.print(previousStateData);
//Serial.print(currentStateData);
//Serial.print(previousStateSW);
//Serial.print(currentStateSW);
Serial.println(" counterclockwise ");
Serial.println("----------------------------");
if (fireTimeMs < fireTimeLowerLimit) {
fireTimeMs = fireTimeLowerLimit;
playMelodieForOverUnderFlow();
}
}
else {
conterclockwiseBool = !conterclockwiseBool;
}
previousStateClock = currentStateClock;
previousStateData = currentStateData;
previousStateSW = currentStateSW;
}
}
lastInterruptTime = currentTime;
sei();
}
/*
ISR(PCINT1_vect) {
cli();
currentStateClock = (PINC >> 0 & 0b00000001 );
currentStateData = (PINC >> 1 & 0b00000001 );
currentStateSW = (PINC >> 2 & 0b00000001 );
unsigned long currentTime = millis();
if (( currentTime - lastInterruptTime) > debounceDelayEncoder ) {
//Serial.println("----------------------------");
//Serial.print("currentStateClock: ");
//Serial.print(currentStateClock);
//Serial.println("");
//Serial.print("previousStateClock: ");
//Serial.print(previousStateClock);
//Serial.println("");
//Serial.print("currentStateData: ");
//Serial.print(currentStateData);
//Serial.println("");
//Serial.print("previousStateData: ");
//Serial.print(previousStateData);
//Serial.println("");
//Serial.print("currentStateSW: ");
//Serial.print(currentStateSW);
//Serial.println("");
if ( ( currentStateClock != previousStateClock || currentStateData != previousStateData) && (currentStateData != HIGH) && (currentStateData != HIGH) ) { //Beide AND-Bed. prüfen ob nicht SW-gedrückt nicht erfüllt ist
if (rotationChanges == POSSIBLE) {
if (( currentStateData == LOW && currentStateClock == HIGH ) || ( currentStateData == HIGH && currentStateClock == LOW ) ) {
// Encoder is rotating clockwise
fireTimeMs += fireTimeStepSize;
encdirection = "Clockwise";
//Serial.println("Fire Time:: ");
//Serial.println(fireTimeMs);
//Serial.println("Rotation: ");
//Serial.println(encdirection);
//Serial.println("----------------------------");
tone(outputBuzzer, selectingFreq, buzzerTimeForSelecting);
//Avoid overcounting
if (fireTimeMs > fireTimeUpperLimit ) {
fireTimeMs = fireTimeUpperLimit;
playMelodieForSelecting();
}
//update the previous State of Clock to th inverted current State of Clock
//to avoid double counting up/down, if bouncing of encoder States triggers ISR
previousStateClock = !currentStateClock;
//previousStateData = !currentStateData; //not needed because changing the previousStateClock is sufficient
}
else {
if ( (currentStateData == HIGH && currentStateClock == HIGH ) || (currentStateData == LOW && currentStateClock == LOW ) ) {
//Encoder is rotating clockwise
fireTimeMs -= fireTimeStepSize;
encdirection = "Countercolckwise";
//Serial.println("Fire Time:: ");
//Serial.println(fireTimeMs);
//Serial.println("Rotation: ");
//Serial.println(encdirection);
//Serial.println("----------------------------");
playMelodieForSelecting();
//Avoid undercounting
if (fireTimeMs < fireTimeLowerLimit) {
fireTimeMs = fireTimeLowerLimit;
tone(outputBuzzer, overUnderFlowFreq, buzzerTimeForSelecting);
}
}
}
//update the previous State of Clock to th inverted current State of Clock
//to avoid double counting up/down if bouncing of encoder States triggers ISR
previousStateClock = !currentStateClock;
//previousStateData = !currentStateData; //not needed because changing the previousStateClock is sufficient
}
}
else {
if (currentStateSW == LOW ) { //Detects at a rising edge for intput_pullup
rotationChanges = IMPOSSIBLE;
lockState = !lockState;
//Serial.println("SW-Buttom pressed");
if (lockState == LOCKED) {
//Serial.println("LOCKED");
playMelodieForLocking();
setupAndStartFootPaddleInterrupt();
}
else {
//Serial.println("UNLOCKED");
playMelodieForUnlocking();
//Disable Timer 1 whether it's set to 1 Sek or 10 ms
TIMSK1 &= ~0b00000010;
timer10msEnabled = false;
//Set Relay-PIN to LOW whether it's set to 1 Sek or 10 ms
PORTC &= ~(1 << 4);
//Set Buzzer-PIN to LOW
PORTC &= ~(1 << 5);
//digitalWrite(outputBuzzer, LOW);
counterOf10ms = 0;
countDownSek = defaultCDValue;
//Always set the timer back to 1 sek after every unlocking
setup16BitTimer1sek();
//Disable Interrupts for Footpadle
PCMSK2 &= ~(1 << 0);
}
}
}
}
lastInterruptTime = currentTime;
sei();
}
*/
ISR(PCINT2_vect) {
cli();
currentFPState = PIND >> 0 & 0b00000001 ;
currentTime = millis();
//Serial.println("Foot paddle Interrupt");
//Serial.print("currentFPState: ");
//Serial.print(currentFPState);
//Serial.println("");
//Serial.print("previousFPState: ");
//Serial.print(previousFPState);
//Serial.println("");
//Serial.print("countDownTimerEnable before change: ");
//Serial.print(countDownTimerEnable);
//Serial.println("");
//Serial.print("currentTime: ");
//Serial.print(currentTime);
//Serial.println("");
//Serial.print("currentTime - lastInterruptTime: ");
//Serial.print((currentTime-lastInterruptTime));
//Serial.println("");
//Serial.println("--------------");
//Do whatever to do if Pin D0 (PD0) (Footpaddle) is triggered
if (( currentTime - lastInterruptTime) > debounceDelayFP) {
if (currentFPState != previousFPState) { //Detects all changes
countDownTimerEnable = !countDownTimerEnable;
//Serial.print("countDownTimerEnable after change: ");
//Serial.print(countDownTimerEnable);
//Serial.println("");
//Serial.println("Footpaddle pressed!");
if ( countDownTimerEnable == true) {
//Serial.println("Fire in ...");
//Serial.println(OCR1A);
//Enable Timer 1
TIMSK1 |= 0b00000010;
//Set Counter for 16-Bit-1Sek-Timer to 0 to start
TCNT1 = 0;
//Serial.print("currentFPState: ");
//Serial.print(currentFPState);
//Serial.println("");
//Serial.print("previousFPState: ");
//Serial.print(previousFPState);
//Serial.println("");
//Serial.print("countDownTimerEnable before change: ");
//Serial.print(countDownTimerEnable);
//Serial.println("");
//Serial.print("currentTime: ");
//Serial.print(currentTime);
//Serial.println("");
//Serial.print("currentTime - lastInterruptTime: ");
//Serial.print((currentTime-lastInterruptTime));
//Serial.println("");
//Serial.println("--------------");
}
else {
//Disable Timer 1
TIMSK1 &= ~0b00000010;
timer10msEnabled = false;
//Set Relay-PIN to LOW
PORTC &= ~(1 << 4);
//Set Buzzer-PIN to LOW
PORTC &= ~(1 << 5);
//digitalWrite(outputBuzzer, LOW);
counterOf10ms = 0;
countDownSek = defaultCDValue;
setup16BitTimer1sek();
//Serial.print("Countdown interrupted at ");
//Serial.print(TCNT1);
//Serial.print(" counts.");
//Serial.println("");
}
//update the previous State of Footpaddle to the inverted current State of Footpaddle
//to avoid double counting up/down if bouncing of encoder States triggers ISR
previousFPState = !currentFPState;
}
}
//lastInterruptTime = millis();
lastInterruptTime = currentTime; //möglicherweise nicht mehr brauchen
sei();
}
ISR(TIMER1_COMPA_vect) {
sei(); /*Ermöglicht es nested Interrupts zu schaffen um die ISR zu unterbrechen, außer es wird der Timer verändert/Interrupts aufgehoben*/
//Ermöglicht es auch während der ISR von 10ms Timer und 1Sek Timer das Relay zu öffnen
//Serial.print("counter of 10ms Timer: ");
//Serial.print(counterOf10ms);
//Serial.println("");
//Serial.print("lockState: ");
//Serial.print(lockState);
//Serial.println("");
//Serial.print("countDownTimerEnable: ");
//Serial.print(countDownTimerEnable);
//Serial.println("");
//Serial.print("timer10msEnabled: ");
//Serial.print(timer10msEnabled);
//Serial.println("---------------------");
if (timer10msEnabled == true) {
//Setup Seven seg-Display-Mode to
counterOf10ms += 1;
//Little workaround for displaying the time on SevenSeg
countDownSek += 10;
TCNT1 = 0;
if (counterOf10ms == maximumCountsOf10ms) {
//Disable Timer 10ms
TIMSK1 &= ~0b00000010;
timer10msEnabled = false;
countDownTimerEnable = false;
//Set Relay-PIN to LOW
PORTC &= ~(1 << 4);
//Set Buzzer-PIN to LOW
PORTC &= ~(1 << 5);
counterOf10ms = 0;
countDownSek = defaultCDValue;
cli();
setup16BitTimer1sek();
sei();
//Serial.println("Firetimer stop");
}
}
else {
if (countDownSek == 1 && lockState == LOCKED && countDownTimerEnable == true && timer10msEnabled == false) { /*Ermöglicht es mit Drücken des SW-Buttom oder Drücken des Footpaddles die ISR zu unterbrechen*/
countDownSek -= 1;
//Disable Timer Interrupts
TIMSK1 &= ~0b00000010;
cli();
setup16BitTimer10ms();
sei();
//countDownTimerEnable = false;
timer10msEnabled = true;
maximumCountsOf10ms = (int) (fireTimeMs / fireTimeStepSize );
//Serial.println("Firetimer start");
//Serial.println(OCR1A);
//Set Relay-PIN to HIGH
PORTC |= (1 << 4);
//digitalWrite(outputRelay, HIGH);
//Set Buzzer-PIN to HIGH
//PORTC |= (1 << 5);
//Start new timer
//Set Counter for 16-Bit-Timer to 0 to start
TCNT1 = 0;
//Enable Timer 1 interrupts
TIMSK1 |= 0b00000010;
}
else {
if (countDownSek > 1 && lockState == LOCKED && countDownTimerEnable == true && timer10msEnabled == false) {/*Ermöglicht es mit Drücken des SW-Buttom oder Drücken des Footpaddles die ISR zu unterbrechen*/
TCNT1 = 0;
playMelodieForCountDown();
countDownSek = countDownSek - 1 ;
//Serial.println(countDownSek);
//Serial.print("counter of 10ms Timer: ");
//Serial.print(counterOf10ms);
//Serial.println("");
//Serial.print("lockState: ");
//Serial.print(lockState);
//Serial.println("");
//Serial.print("countDownTimerEnable: ");
//Serial.print(countDownTimerEnable);
//Serial.println("");
//Serial.print("timer10msEnabled: ");
//Serial.print(timer10msEnabled);
//Serial.println("---------------------");
}
}
}
//Serial.println("Timer interrupt");
}