aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpro100sasho <65253560+pro100sasho@users.noreply.github.com>2020-06-23 22:45:32 +0300
committerpro100sasho <65253560+pro100sasho@users.noreply.github.com>2020-06-23 22:45:32 +0300
commit40e0d86c1364b1f0c2395a42c5e1b49730b7e31e (patch)
tree9570b1ef0ca0424f81944e5ecd7e9a20d6461bc1
parente5fbf1ead67d6b7c5cc4adb219ddf0833dff8bc4 (diff)
downloadRemiHap-40e0d86c1364b1f0c2395a42c5e1b49730b7e31e.tar
RemiHap-40e0d86c1364b1f0c2395a42c5e1b49730b7e31e.tar.gz
RemiHap-40e0d86c1364b1f0c2395a42c5e1b49730b7e31e.zip
Added Alarm MicroController Code
-rw-r--r--Code from circuits/Alarm/Alarm.ino104
1 files changed, 104 insertions, 0 deletions
diff --git a/Code from circuits/Alarm/Alarm.ino b/Code from circuits/Alarm/Alarm.ino
new file mode 100644
index 0000000..7ad8a31
--- /dev/null
+++ b/Code from circuits/Alarm/Alarm.ino
@@ -0,0 +1,104 @@
+#include <Adafruit_NeoPixel.h>
+
+#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 BTN_PIN 2
+#define STRIP_PIN 3
+#define LED_COUNT 4
+#define PIEZZO_PIN 5
+
+#define MELODY_LENGTH 4
+
+int melodies[2][MELODY_LENGTH] =
+{
+ {NOTE_C5, NOTE_E5, NOTE_D5, 0},
+ {NOTE_C5, NOTE_C5, NOTE_C5, NOTE_C5}
+};
+
+int noteDurations[] =
+{
+ 1000 / 8, 1000 / 8, 1000 / 8, 1000 / 2
+};
+
+Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, STRIP_PIN, NEO_GRB + NEO_KHZ800);
+unsigned long color = strip.Color(255, 255, 255);
+
+bool ButtonIsPressed()
+{
+ return digitalRead(BTN_PIN) == 1;
+}
+
+void ledToggle()
+{
+ if(strip.getPixelColor(0) == strip.Color(0,0,0))
+ {
+ strip.fill(color);
+ }
+ else
+ {
+ strip.clear();
+ }
+ strip.show();
+}
+
+void playNote(int noteDuration, int noteToPlay)
+{
+ tone(PIEZZO_PIN, noteToPlay, noteDuration);
+ delay(noteDuration * 1.30);
+
+ noTone(PIEZZO_PIN);
+}
+
+void PlayMelodyAndLEDs(int position)
+{
+ for(int i = 0; i < MELODY_LENGTH; i++)
+ {
+ playNote(noteDurations[i], melodies[position][i]);
+ ledToggle();
+ delay(100);
+
+ }
+}
+
+void setup()
+{
+ pinMode(BTN_PIN, INPUT);
+ pinMode(STRIP_PIN, OUTPUT);
+ pinMode(PIEZZO_PIN, OUTPUT);
+ strip.begin();
+}
+
+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);
+ }
+ }
+}
+
+
+
+void loop()
+{
+ if(ButtonIsPressed())
+ {
+ Alarm(millis());
+ }
+ delay(100);
+}
+