#include int ledPin = 8; int buttonPin = 7; int ditMs = 100; int dahMs = 3 * ditMs; int delayBetweenCharacters = 2 * ditMs; //theoretically, this is 3 dit, but 1 dit is already included in the dit and dah functions int delayBetweenSos = 6 * ditMs; //theoretically, this is 7 dit, but 1 dit is already included in the dit and dah functions int buzzerPin = 11 ; // Deklaration des Buzzer-Ausgangspin long buzzerLast = 0; long buzzerNow = 0; int buzzerFrequency = 220; int buzzerIntervalMillis = 1000/buzzerFrequency/2; int buzzerIntervalMicros = 1000000/buzzerFrequency/2; boolean buzzerState = 0; void setup() { clock_prescale_set(0); pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); digitalWrite(buttonPin, HIGH); //Internal pullup on Button Pin pinMode (buzzerPin, OUTPUT) ;// Initialisierung als Ausgangspin //beep(buzzerPin, 1000); //delay(1000); //beep(buzzerPin, 500); //delay(1000); //beep(buzzerPin, 250); //delay(1000); } void loop() { if(digitalRead(buttonPin) != LOW){ /*digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000);*/ //sosBlink(ledPin); sosBeep(buzzerPin); delay(delayBetweenSos); } } void dit(int blinkPin){ digitalWrite(blinkPin, HIGH); delay(ditMs); digitalWrite(blinkPin, LOW); delay(ditMs); } void dah(int blinkPin){ digitalWrite(blinkPin, HIGH); delay(dahMs); digitalWrite(blinkPin, LOW); delay(ditMs); } void sosBlink(int blinkPin){ dit(blinkPin); dit(blinkPin); dit(blinkPin); delay(delayBetweenCharacters); dah(blinkPin); dah(blinkPin); dah(blinkPin); delay(delayBetweenCharacters); dit(blinkPin); dit(blinkPin); dit(blinkPin); } void ditBeep(int buzzerPin){ beep(buzzerPin, ditMs); delay(ditMs); } void dahBeep(int buzzerPin){ beep(buzzerPin, dahMs); delay(ditMs); } void sosBeep(int buzzerPin){ ditBeep(buzzerPin); ditBeep(buzzerPin); ditBeep(buzzerPin); delay(delayBetweenCharacters); dahBeep(buzzerPin); dahBeep(buzzerPin); dahBeep(buzzerPin); delay(delayBetweenCharacters); ditBeep(buzzerPin); ditBeep(buzzerPin); ditBeep(buzzerPin); } void beep(int buzzerPin, int duration){ long start = millis(); while((millis()-start) < duration){ buzzerNow = micros(); if((buzzerNow - buzzerLast) >= buzzerIntervalMicros){ buzzerLast = buzzerNow; buzzerState = !buzzerState; digitalWrite(buzzerPin, buzzerState); } } }