From 8a55a9810c2ae2f8d00be456d9c7295dd44c7509 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 23 Jun 2020 22:52:36 +0300 Subject: Fixed inconsistent/bad formatting in Alarm microcontroller code --- Code from circuits/Alarm/Alarm.ino | 71 ++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/Code from circuits/Alarm/Alarm.ino b/Code from circuits/Alarm/Alarm.ino index 7ad8a31..44fed37 100644 --- a/Code from circuits/Alarm/Alarm.ino +++ b/Code from circuits/Alarm/Alarm.ino @@ -1,24 +1,25 @@ #include +//Defining the notes' frequencies for the melody #define NOTE_C5 523 #define NOTE_D5 587 #define NOTE_E5 659 -//Defining the notes' frequencies for the melody -#define interval 10000 //Time in millisecconds between first and second alarm +#define interval 10000 #define BTN_PIN 2 #define STRIP_PIN 3 -#define LED_COUNT 4 #define PIEZZO_PIN 5 +#define LED_COUNT 4 + #define MELODY_LENGTH 4 int melodies[2][MELODY_LENGTH] = { - {NOTE_C5, NOTE_E5, NOTE_D5, 0}, - {NOTE_C5, NOTE_C5, NOTE_C5, NOTE_C5} + { NOTE_C5, NOTE_E5, NOTE_D5, 0 }, + { NOTE_C5, NOTE_C5, NOTE_C5, NOTE_C5 } }; int noteDurations[] = @@ -37,32 +38,31 @@ bool ButtonIsPressed() void ledToggle() { if(strip.getPixelColor(0) == strip.Color(0,0,0)) - { - strip.fill(color); - } - else - { - strip.clear(); - } - strip.show(); + { + strip.fill(color); + } + else + { + strip.clear(); + } + strip.show(); } void playNote(int noteDuration, int noteToPlay) { - tone(PIEZZO_PIN, noteToPlay, noteDuration); - delay(noteDuration * 1.30); + tone(PIEZZO_PIN, noteToPlay, noteDuration); + delay(noteDuration * 1.30); - noTone(PIEZZO_PIN); + noTone(PIEZZO_PIN); } void PlayMelodyAndLEDs(int position) { - for(int i = 0; i < MELODY_LENGTH; i++) + for(int i = 0; i < MELODY_LENGTH; i++) { - playNote(noteDurations[i], melodies[position][i]); - ledToggle(); - delay(100); - + playNote(noteDurations[i], melodies[position][i]); + ledToggle(); + delay(100); } } @@ -76,23 +76,21 @@ void setup() void Alarm(unsigned long timeSinceActivation) { - while(ButtonIsPressed()) - { - if(millis() - timeSinceActivation > interval) - { - color = strip.Color(255, 0, 0); - PlayMelodyAndLEDs(1); - } - else - { - color = strip.Color(255, 255, 0); - PlayMelodyAndLEDs(0); - } - } + while(ButtonIsPressed()) + { + if(millis() - timeSinceActivation > interval) + { + color = strip.Color(255, 0, 0); + PlayMelodyAndLEDs(1); + } + else + { + color = strip.Color(255, 255, 0); + PlayMelodyAndLEDs(0); + } + } } - - void loop() { if(ButtonIsPressed()) @@ -101,4 +99,3 @@ void loop() } delay(100); } - -- cgit v1.2.3