Stimer za gitaru

Dependencies:   mbed

Komponente: 7 segmentni display, Piezzo buzzer, tipkalo i NUCLEO-F072RB

Uređaj funkcionira kao muzički ključ za naštimavanje gitare u standardni štim (EADGBe). Kad se uređaj upali, piezzo zvučnik počinje proizvoditi ton koji bi pripadao najdebljoj žici (E – 82,41 Hz). Većina ljudi nema apsolutni sluh pa se zato koristi sedam segmentni display koji prikazuje kojoj noti pripada frekvencija koju piezzo zvučnik reproducira. Pritiskom na tipkalo desi se hardverski prekid, te uređaj počinje reproducirati frekvenciju iduće note (npr. nakon note E, reproducira se nota A) te se oznaka te note prikazuje na sedam segmentnom displayu. Kada uređaj dođe do zadnje note (e – 329,63 Hz), pritiskom na tipku vraća se na prvu notu (E – 82,41 Hz). Korišten je ticker kako bi se svake dvije sekunde zvuk prestao reproducirati, kako bismo mogli dobiti bolju ideju koju frekvenciju proizvodi instrument koji naštimavamo. Frekvencije koje piezzo zvučnik reproducira zapravo nisu točno te frekvencije na koje bismo trebali naštimati instrument. Razlog je fenomen koji se pojavio kod reprodukcije G note. Piezzo zvučnik je iz nekog razloga reproducirao frekvencije tona G i tona G#. Kako bi se izbjegao taj fenomen reproducirane frekvencije duplo veće (oktava).

https://os.mbed.com/media/uploads/jurajplesa/schema.png

Files at this revision

API Documentation at this revision

Comitter:
jurajplesa
Date:
Thu Dec 09 15:51:58 2021 +0000
Commit message:
Stimer za gitaru V1

Changed in this revision

Segment.cpp Show annotated file Show diff for this revision Revisions of this file
Segment.h Show annotated file Show diff for this revision Revisions of this file
Tune.cpp Show annotated file Show diff for this revision Revisions of this file
Tune.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Segment.cpp	Thu Dec 09 15:51:58 2021 +0000
@@ -0,0 +1,27 @@
+#include "Segment.h"
+
+BusOut Seg1(D5,D6,D7,D8,D9,D10,D11,D12);
+
+void segmentac()
+{
+    switch (i) { //DPGFEDCBA
+        case 0 :
+            Seg1 = 0x79;
+            break;
+        case 1 :
+            Seg1 = 0x77;
+            break;
+        case 2 :
+            Seg1 = 0x5E;
+            break;
+        case 3 :
+            Seg1 = 0x7D;
+            break;
+        case 4 :
+            Seg1 = 0x7C;
+            break;
+        case 5 :
+            Seg1 = 0x79;
+            break;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Segment.h	Thu Dec 09 15:51:58 2021 +0000
@@ -0,0 +1,9 @@
+#ifndef SEGMENT_H
+#define SEGMENT_H
+#include "mbed.h"
+
+extern int i;
+
+void segmentac(void);
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tune.cpp	Thu Dec 09 15:51:58 2021 +0000
@@ -0,0 +1,45 @@
+#include "Tune.h"
+
+InterruptIn button(D2);
+PwmOut buzzer(D14);
+Timer debounce;
+Ticker flipper;
+
+int svira=1;
+float frequency[]= {82.41, 110.00, 146.83, 196.00, 246.94, 329.63};
+
+void TuneInit()
+{
+    debounce.start();
+    button.rise(&toggle);
+    flipper.attach(&piezo, 2);
+}
+
+void toggle()
+{
+    if (debounce.read_ms()>200) {
+        inkrementatitator();
+    }
+    debounce.reset();
+}
+
+void inkrementatitator()
+{
+    if(i==5) {
+        i=0;
+    } else {
+        i++;
+    }
+}
+
+void piezo()
+{
+    if(svira==1) {
+        svira=0;
+        buzzer.period(1/((frequency[i])*2));
+        buzzer=0.5;
+    } else {
+        buzzer=0;
+        svira=1;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tune.h	Thu Dec 09 15:51:58 2021 +0000
@@ -0,0 +1,12 @@
+#ifndef TUNE_H
+#define TUNE_H
+#include "mbed.h"
+
+extern int i;
+
+void TuneInit(void);
+void toggle(void);
+void piezo(void);
+void inkrementatitator(void);
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 09 15:51:58 2021 +0000
@@ -0,0 +1,13 @@
+#include "mbed.h"
+#include "Tune.h"
+#include "Segment.h"
+
+int i=0;
+
+int main()
+{
+    TuneInit();
+    while (1) {
+        segmentac();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 09 15:51:58 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file