commit 3cb1d71747bf4821a5a6a73c1b95dad868f96bc8 Author: Alexander Lehr Date: Mon Nov 27 17:42:21 2023 +0100 init diff --git a/Aufgabe_3_1_2/sketch_nov3a/sketch_nov3a.ino b/Aufgabe_3_1_2/sketch_nov3a/sketch_nov3a.ino new file mode 100644 index 0000000..c7c9b20 --- /dev/null +++ b/Aufgabe_3_1_2/sketch_nov3a/sketch_nov3a.ino @@ -0,0 +1,91 @@ +#include /* Hardware-Definitionen */ +#include +#include /* Für uint8_t */ +#include "keys.h" /* Notennummern und -dauern */ + +/* Anzahl der Einzelschritte in der Melodie */ +#define NOTE_COUNT 71 + +/* Tempo in Schlägen pro Minute */ +#define TEMPO 103 + + +uint8_t note_pitches[NOTE_COUNT] = { + KEY_G3, KEY_G3, KEY_G3, KEY_Eb3, KEY_Bb3, + KEY_G3, KEY_Eb3, KEY_B3, KEY_G3, + KEY_D4, KEY_D4, KEY_D4, KEY_Eb4, KEY_Bb3, + KEY_Gb3, KEY_Eb3, KEY_Bb3, KEY_G3, + + KEY_G4, KEY_G3, KEY_G3, KEY_G4, KEY_Fis4, KEY_F4, + KEY_E4, KEY_Dis4, KEY_E4, PAUSE, KEY_Gis3, KEY_Cis4, KEY_C4, KEY_B3, + KEY_Bb3, KEY_A3, KEY_Bb3, PAUSE, KEY_Eb3, KEY_Gb3, KEY_Eb3, KEY_Gb3, + KEY_G3, KEY_G3, KEY_Bb3, KEY_D4, + + KEY_G4, KEY_G3, KEY_G3, KEY_G4, KEY_Fis4, KEY_F4, + KEY_E4, KEY_Dis4, KEY_E4, PAUSE, KEY_Gis3, KEY_Cis4, KEY_C4, KEY_B3, + KEY_Bb3, KEY_A3, KEY_Bb3, PAUSE, KEY_Eb3, KEY_Gb3, KEY_Eb3, KEY_Bb3, + + KEY_G3, KEY_Eb3, KEY_Bb3, KEY_G3, + + PAUSE +}; + +/* Tonlängen (in 1/48-Noten) */ +uint8_t note_durations[NOTE_COUNT] = { + DUR_4th, DUR_4th, DUR_4th, DUR_8th_dot, DUR_16th, + DUR_4th, DUR_8th_dot, DUR_16th, DUR_half, + DUR_4th, DUR_4th, DUR_4th, DUR_8th_dot, DUR_16th, + + DUR_4th, DUR_8th_dot, DUR_16th, DUR_half, + DUR_4th, DUR_8th_dot, DUR_16th, DUR_4th, DUR_8th_dot, DUR_16th, + DUR_16th, DUR_16th, DUR_8th, DUR_8th, DUR_8th, DUR_4th, DUR_8th_dot, DUR_16th, + + DUR_16th, DUR_16th, DUR_8th, DUR_8th, DUR_8th, DUR_4th, DUR_8th_dot, DUR_16th, + DUR_4th, DUR_8th_dot, DUR_16th, DUR_half, + DUR_4th, DUR_8th_dot, DUR_16th, DUR_4th, DUR_8th_dot, DUR_16th, + + DUR_16th, DUR_16th, DUR_8th, DUR_8th, DUR_8th, DUR_4th, DUR_8th_dot, DUR_16th, + DUR_16th, DUR_16th, DUR_8th, DUR_8th, DUR_8th, DUR_4th, DUR_8th_dot, DUR_16th, + DUR_4th, DUR_8th_dot, DUR_16th, DUR_half, + + DUR_whole +}; + +int main(int argc, char** argv) { + + + // Tasterpin als Eingang konfigurieren + DDRD &= ~(1 << 6); + // Pull-up Widerstand für den Taster aktivieren + PORTD |= (1 << 6); + + int i = 2; + + bool pressed = false; + + while (1) { + + if (!(PIND & (1 << 6))) { + pressed = true; + } + + if(pressed) { + + DDRD = (1< + \ No newline at end of file diff --git a/Aufgabe_4/.idea/editor.xml b/Aufgabe_4/.idea/editor.xml new file mode 100644 index 0000000..46540da --- /dev/null +++ b/Aufgabe_4/.idea/editor.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Aufgabe_4/.idea/misc.xml b/Aufgabe_4/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/Aufgabe_4/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Aufgabe_4/.idea/modules.xml b/Aufgabe_4/.idea/modules.xml new file mode 100644 index 0000000..fb4a158 --- /dev/null +++ b/Aufgabe_4/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Aufgabe_4/.vscode/extensions.json b/Aufgabe_4/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/Aufgabe_4/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/Aufgabe_4/cmake-build-debug/CMakeFiles/clion-Debug-log.txt b/Aufgabe_4/cmake-build-debug/CMakeFiles/clion-Debug-log.txt new file mode 100644 index 0000000..d6e8f8a --- /dev/null +++ b/Aufgabe_4/cmake-build-debug/CMakeFiles/clion-Debug-log.txt @@ -0,0 +1 @@ +CMakeLists.txt not found in /Users/alexanderlehr/Nextcloud/Studium/Semester 3/Rechnerarchitektur/Aufgabe_4 Select CMakeLists.txt diff --git a/Aufgabe_4/include/README b/Aufgabe_4/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/Aufgabe_4/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/Aufgabe_4/lib/README b/Aufgabe_4/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/Aufgabe_4/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/Aufgabe_4/platformio.ini b/Aufgabe_4/platformio.ini new file mode 100644 index 0000000..ea23b77 --- /dev/null +++ b/Aufgabe_4/platformio.ini @@ -0,0 +1,14 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:uno] +platform = atmelavr +board = uno +framework = arduino diff --git a/Aufgabe_4/src/Notenhöhen.xlsx b/Aufgabe_4/src/Notenhöhen.xlsx new file mode 100644 index 0000000..3a125d0 Binary files /dev/null and b/Aufgabe_4/src/Notenhöhen.xlsx differ diff --git a/Aufgabe_4/src/fuer_elise.h b/Aufgabe_4/src/fuer_elise.h new file mode 100644 index 0000000..1e7dc28 --- /dev/null +++ b/Aufgabe_4/src/fuer_elise.h @@ -0,0 +1,44 @@ +/* Melodie für "Fuer Elise" von Ludwig van Beethoven (1770-1827) */ +#ifndef FUER_ELISE_H +#define FUER_ELISE_H + +#include /* Für uint8_t */ +#include "keys.h" /* Notennummern und -dauern */ + +/* Anzahl der Einzelschritte in der Melodie */ +#define NOTE_COUNT 40 + +/* Tempo in Schlägen pro Minute */ +#define TEMPO 68 + +/* Tonhöhen */ +uint8_t note_pitches[NOTE_COUNT] = { + KEY_E5, KEY_Dis5, + KEY_E5, KEY_Dis5, KEY_E5, KEY_B4, KEY_D5, KEY_C5, + KEY_A4, PAUSE, KEY_C4, KEY_E4, KEY_A4, + KEY_B4, PAUSE, KEY_E4, KEY_Gis4, KEY_B4, + KEY_C5, PAUSE, KEY_E4, KEY_E5, KEY_Dis5, + + KEY_E5, KEY_Dis5, KEY_E5, KEY_B4, KEY_D5, KEY_C5, + KEY_A4, PAUSE, KEY_C4, KEY_E4, KEY_A4, + KEY_B4, PAUSE, KEY_D4, KEY_C5, KEY_B4, + KEY_A4, +}; + +/* Tonlängen (in 1/48-Noten) */ +uint8_t note_durations[NOTE_COUNT] = { + /* Zeile 1 */ + DUR_16th, DUR_16th, + DUR_16th, DUR_16th, DUR_16th, DUR_16th, DUR_16th, DUR_16th, + DUR_8th, DUR_16th, DUR_16th, DUR_16th, DUR_16th, + DUR_8th, DUR_16th, DUR_16th, DUR_16th, DUR_16th, + DUR_8th, DUR_16th, DUR_16th, DUR_16th, DUR_16th, + + /* Zeile 2 */ + DUR_16th, DUR_16th, DUR_16th, DUR_16th, DUR_16th, DUR_16th, + DUR_8th, DUR_16th, DUR_16th, DUR_16th, DUR_16th, + DUR_8th, DUR_16th, DUR_16th, DUR_16th, DUR_16th, + DUR_4th, +}; + +#endif /* FUER_ELISE_H */ diff --git a/Aufgabe_4/src/imperial_march.h b/Aufgabe_4/src/imperial_march.h new file mode 100644 index 0000000..9917db1 --- /dev/null +++ b/Aufgabe_4/src/imperial_march.h @@ -0,0 +1,57 @@ +/* Melodie für den "Imperial March" aus Star Wars (1977) */ +#ifndef IMPERIAL_MARCH_H +#define IMPERIAL_MARCH_H + +#include /* Für uint8_t */ +#include "keys.h" /* Notennummern und -dauern */ + +/* Anzahl der Einzelschritte in der Melodie */ +#define NOTE_COUNT 71 + +/* Tempo in Schlägen pro Minute */ +#define TEMPO 103 + +/* Tonhöhen */ +// es, b +uint8_t note_pitches[NOTE_COUNT] = { + KEY_G3, KEY_G3, KEY_G3, KEY_Eb3, KEY_Bb3, + KEY_G3, KEY_Eb3, KEY_B3, KEY_G3, + KEY_D4, KEY_D4, KEY_D4, KEY_Eb4, KEY_Bb3, + KEY_Gb3, KEY_Eb3, KEY_Bb3, KEY_G3, + + KEY_G4, KEY_G3, KEY_G3, KEY_G4, KEY_Fis4, KEY_F4, + KEY_E4, KEY_Dis4, KEY_E4, PAUSE, KEY_Gis3, KEY_Cis4, KEY_C4, KEY_B3, + KEY_Bb3, KEY_A3, KEY_Bb3, PAUSE, KEY_Eb3, KEY_Gb3, KEY_Eb3, KEY_Gb3, + KEY_G3, KEY_G3, KEY_Bb3, KEY_D4, + + KEY_G4, KEY_G3, KEY_G3, KEY_G4, KEY_Fis4, KEY_F4, + KEY_E4, KEY_Dis4, KEY_E4, PAUSE, KEY_Gis3, KEY_Cis4, KEY_C4, KEY_B3, + KEY_Bb3, KEY_A3, KEY_Bb3, PAUSE, KEY_Eb3, KEY_Gb3, KEY_Eb3, KEY_Bb3, + + KEY_G3, KEY_Eb3, KEY_Bb3, KEY_G3, + + PAUSE +}; + +/* Tonlängen (in 1/48-Noten) */ +uint8_t note_durations[NOTE_COUNT] = { + DUR_4th, DUR_4th, DUR_4th, DUR_8th_dot, DUR_16th, + DUR_4th, DUR_8th_dot, DUR_16th, DUR_half, + DUR_4th, DUR_4th, DUR_4th, DUR_8th_dot, DUR_16th, + + DUR_4th, DUR_8th_dot, DUR_16th, DUR_half, + DUR_4th, DUR_8th_dot, DUR_16th, DUR_4th, DUR_8th_dot, DUR_16th, + DUR_16th, DUR_16th, DUR_8th, DUR_8th, DUR_8th, DUR_4th, DUR_8th_dot, DUR_16th, + + DUR_16th, DUR_16th, DUR_8th, DUR_8th, DUR_8th, DUR_4th, DUR_8th_dot, DUR_16th, + DUR_4th, DUR_8th_dot, DUR_16th, DUR_half, + DUR_4th, DUR_8th_dot, DUR_16th, DUR_4th, DUR_8th_dot, DUR_16th, + + DUR_16th, DUR_16th, DUR_8th, DUR_8th, DUR_8th, DUR_4th, DUR_8th_dot, DUR_16th, + DUR_16th, DUR_16th, DUR_8th, DUR_8th, DUR_8th, DUR_4th, DUR_8th_dot, DUR_16th, + DUR_4th, DUR_8th_dot, DUR_16th, DUR_half, + + DUR_whole +}; + +#endif /* IMPERIAL_MARCH_H */ diff --git a/Aufgabe_4/src/keys.h b/Aufgabe_4/src/keys.h new file mode 100644 index 0000000..af115cc --- /dev/null +++ b/Aufgabe_4/src/keys.h @@ -0,0 +1,186 @@ +#ifndef KEYS_H +#define KEYS_H + +/* Notendauern in 1/96 */ +#define DUR_16th_tri 4 /* 16tel-Triole */ +#define DUR_16th 6 /* 16tel-Note */ +#define DUR_8th_tri 8 /* 8-tel-Note mit Punkt */ +#define DUR_16th_dot 9 /* 16tel-Note mit Punkt */ +#define DUR_8th 12 /* 8-tel-Note */ +#define DUR_4th_tri 16 /* 4-tel-Triole */ +#define DUR_8th_dot 18 /* 8-tel-Note mit Punkt*/ +#define DUR_4th 24 /* 4-tel-Note */ +#define DUR_half_tri 32 /* Halbetriole */ +#define DUR_4th_dot 36 /* 4-tel-Note mit Punkt */ +#define DUR_half 48 /* halbe Note */ +#define DUR_half_dot 72 /* halbe Note mit Punkt */ +#define DUR_whole 96 /* ganze Note */ +#define DUR_whole_dot 144 /* ganze Note mit Punkt */ + +/* Notennummern */ + +/* Pausen-Marker */ +#define PAUSE 0 + +/* Basis-Nummern */ +#define KEY_C 0 +#define KEY_Cis 1 +#define KEY_D 2 +#define KEY_Dis 3 +#define KEY_E 4 +#define KEY_F 5 +#define KEY_Fis 6 +#define KEY_G 7 +#define KEY_Gis 8 +#define KEY_A 9 +#define KEY_Ais 10 +#define KEY_B 11 + + +/* Hilfsmakro für Oktaven-Umrechnung */ +#define KEY(base, octave) ((base)+12*(octave)-8) + +/* Oktave 0 */ +#define KEY_A0 KEY(KEY_A, 0) +#define KEY_Ais0 KEY(KEY_Ais, 0) +#define KEY_Bb0 KEY_Ais0 +#define KEY_B0 KEY(KEY_B, 0) + +/* Oktave 1 */ +#define KEY_C1 KEY(KEY_C, 1) +#define KEY_Cis1 KEY(KEY_Cis, 1) +#define KEY_Db1 KEY_Cis1 +#define KEY_D1 KEY(KEY_D, 1) +#define KEY_Dis1 KEY(KEY_Dis, 1) +#define KEY_Eb1 KEY_Dis1 +#define KEY_E1 KEY(KEY_E, 1) +#define KEY_F1 KEY(KEY_F, 1) +#define KEY_Fis1 KEY(KEY_Fis, 1) +#define KEY_Gb1 KEY_Fis1 +#define KEY_G1 KEY(KEY_G, 1) +#define KEY_Gis1 KEY(KEY_Gis, 1) +#define KEY_Ab1 KEY_Gis1 +#define KEY_A1 KEY(KEY_A, 1) +#define KEY_Ais1 KEY(KEY_Ais, 1) +#define KEY_Bb1 KEY_Ais1 +#define KEY_B1 KEY(KEY_B, 1) + +/* Oktave 2 */ +#define KEY_C2 KEY(KEY_C, 2) +#define KEY_Cis2 KEY(KEY_Cis, 2) +#define KEY_Db2 KEY_Cis2 +#define KEY_D2 KEY(KEY_D, 2) +#define KEY_Dis2 KEY(KEY_Dis, 2) +#define KEY_Eb2 KEY_Dis2 +#define KEY_E2 KEY(KEY_E, 2) +#define KEY_F2 KEY(KEY_F, 2) +#define KEY_Fis2 KEY(KEY_Fis, 2) +#define KEY_Gb2 KEY_Fis2 +#define KEY_G2 KEY(KEY_G, 2) +#define KEY_Gis2 KEY(KEY_Gis, 2) +#define KEY_Ab2 KEY_Gis2 +#define KEY_A2 KEY(KEY_A, 2) +#define KEY_Ais2 KEY(KEY_Ais, 2) +#define KEY_Bb2 KEY_Ais2 +#define KEY_B2 KEY(KEY_B, 2) + +/* Oktave 3 */ +#define KEY_C3 KEY(KEY_C, 3) +#define KEY_Cis3 KEY(KEY_Cis, 3) +#define KEY_Db3 KEY_Cis3 +#define KEY_D3 KEY(KEY_D, 3) +#define KEY_Dis3 KEY(KEY_Dis, 3) +#define KEY_Eb3 KEY_Dis3 +#define KEY_E3 KEY(KEY_E, 3) +#define KEY_F3 KEY(KEY_F, 3) +#define KEY_Fis3 KEY(KEY_Fis, 3) +#define KEY_Gb3 KEY_Fis3 +#define KEY_G3 KEY(KEY_G, 3) +#define KEY_Gis3 KEY(KEY_Gis, 3) +#define KEY_Ab3 KEY_Gis3 +#define KEY_A3 KEY(KEY_A, 3) +#define KEY_Ais3 KEY(KEY_Ais, 3) +#define KEY_Bb3 KEY_Ais3 +#define KEY_B3 KEY(KEY_B, 3) + +/* Oktave 4 */ +#define KEY_C4 KEY(KEY_C, 4) +#define KEY_Cis4 KEY(KEY_Cis, 4) +#define KEY_Db4 KEY_Cis4 +#define KEY_D4 KEY(KEY_D, 4) +#define KEY_Dis4 KEY(KEY_Dis, 4) +#define KEY_Eb4 KEY_Dis4 +#define KEY_E4 KEY(KEY_E, 4) +#define KEY_F4 KEY(KEY_F, 4) +#define KEY_Fis4 KEY(KEY_Fis, 4) +#define KEY_Gb4 KEY_Fis4 +#define KEY_G4 KEY(KEY_G, 4) +#define KEY_Gis4 KEY(KEY_Gis, 4) +#define KEY_Ab4 KEY_Gis4 +#define KEY_A4 KEY(KEY_A, 4) +#define KEY_Ais4 KEY(KEY_Ais, 4) +#define KEY_Bb4 KEY_Ais4 +#define KEY_B4 KEY(KEY_B, 4) + +/* Oktave 5 */ +#define KEY_C5 KEY(KEY_C, 5) +#define KEY_Cis5 KEY(KEY_Cis, 5) +#define KEY_Db5 KEY_Cis5 +#define KEY_D5 KEY(KEY_D, 5) +#define KEY_Dis5 KEY(KEY_Dis, 5) +#define KEY_Eb5 KEY_Dis5 +#define KEY_E5 KEY(KEY_E, 5) +#define KEY_F5 KEY(KEY_F, 5) +#define KEY_Fis5 KEY(KEY_Fis, 5) +#define KEY_Gb5 KEY_Fis5 +#define KEY_G5 KEY(KEY_G, 5) +#define KEY_Gis5 KEY(KEY_Gis, 5) +#define KEY_Ab5 KEY_Gis5 +#define KEY_A5 KEY(KEY_A, 5) +#define KEY_Ais5 KEY(KEY_Ais, 5) +#define KEY_Bb5 KEY_Ais5 +#define KEY_B5 KEY(KEY_B, 5) + +/* Oktave 6 */ +#define KEY_C6 KEY(KEY_C, 6) +#define KEY_Cis6 KEY(KEY_Cis, 6) +#define KEY_Db6 KEY_Cis6 +#define KEY_D6 KEY(KEY_D, 6) +#define KEY_Dis6 KEY(KEY_Dis, 6) +#define KEY_Eb6 KEY_Dis6 +#define KEY_E6 KEY(KEY_E, 6) +#define KEY_F6 KEY(KEY_F, 6) +#define KEY_Fis6 KEY(KEY_Fis, 6) +#define KEY_Gb6 KEY_Fis6 +#define KEY_G6 KEY(KEY_G, 6) +#define KEY_Gis6 KEY(KEY_Gis, 6) +#define KEY_Ab6 KEY_Gis6 +#define KEY_A6 KEY(KEY_A, 6) +#define KEY_Ais6 KEY(KEY_Ais, 6) +#define KEY_Bb6 KEY_Ais6 +#define KEY_B6 KEY(KEY_B, 6) + +/* Oktave 7 */ +#define KEY_C7 KEY(KEY_C, 7) +#define KEY_Cis7 KEY(KEY_Cis, 7) +#define KEY_Db7 KEY_Cis7 +#define KEY_D7 KEY(KEY_D, 7) +#define KEY_Dis7 KEY(KEY_Dis, 7) +#define KEY_Eb7 KEY_Dis7 +#define KEY_E7 KEY(KEY_E, 7) +#define KEY_F7 KEY(KEY_F, 7) +#define KEY_Fis7 KEY(KEY_Fis, 7) +#define KEY_Gb7 KEY_Fis7 +#define KEY_G7 KEY(KEY_G, 7) +#define KEY_Gis7 KEY(KEY_Gis, 7) +#define KEY_Ab7 KEY_Gis7 +#define KEY_A7 KEY(KEY_A, 7) +#define KEY_Ais7 KEY(KEY_Ais, 7) +#define KEY_Bb7 KEY_Ais7 +#define KEY_B7 KEY(KEY_B, 7) + +/* Oktave 8 */ +#define KEY_C8 KEY(KEY_C, 8) + + +#endif /* KEYS_H */ diff --git a/Aufgabe_4/src/main.cpp b/Aufgabe_4/src/main.cpp new file mode 100644 index 0000000..3c34962 --- /dev/null +++ b/Aufgabe_4/src/main.cpp @@ -0,0 +1,83 @@ +/* + * Tonerzeugung: + * - Rechteckwelle wird über Timer1 im CTC-Mode erzeugt. + * - Output Compare für OC1A ist Toggle on Compare Match. + * - Timer 1 Prescaler wird auf 1/8 gesetzt + * - Die halbe Periodendauer schreiben wir in OCR1A. + * + * Tempo: + * - TEMPO gibt die Zahl der 1/4-Notendauern an + * - Wir brauchen 1/96-Notendauern. + * - Es gibt 24*TEMPO 1/96-Notendauern pro Sekunde. + * - Mit dem höchsten Prescaler 1/1024 können wir diese Länge nicht direkt erreichen. + * - Wir wählen den Prescaler 1/256 und zählen dann Takte anhand des TOV1-Flags. + * - Das entspricht einem Overflow-Takt von ca. 244Hz. + */ + +// COM1A1:COM1A0 = 01b (in TCCR1A) +// WGM13:WGM10 = 0100b (WGM11:WGM10 in TCCR1A, WGM13:WGM12 in TCCR1B) +// CS12:CS10 = 010b (in TCCR1B) +// OCR1A = Dauer der Halbwelle + +#include +#include +#include "keys.h" +#include "fuer_elise.h" +#include +#include "math.h" + +#define SPEAKER_PIN 0b10 +#define BUTTON_PIN 0b1 + +long int timerarray[] = + { + 36364, 34323, 32396, 30578, 28862, 27242, 25713, 24270, + 22908, 21622, 20408, 19263, 18182, 17161, 16198, 15289, + 14431, 13621, 12856, 12135, 11454, 10811, 10204, 9631, + 9091, 8581, 8099, 7645, 7215, 6810, 6428, 6067, 5727, + 5405, 5102, 4816, 4545, 4290, 4050, 3822, 3608, 3405, + 3214, 3034, 2863, 2703, 2551, 2408, 2273, 2145, 2025, + 1911, 1804, 1703, 1607, 1517, 1432, 1351, 1276, 1204, + 1136, 1073, 1012, 956, 902, 851, 804, 758, 716, 676, 638, 602, + 568, 536, 506, 478, 451, 426, 402, 379, 358, 338, 319, 301, 284, + 268, 253, 239 + }; + +bool sound = false; + +ISR(TIMER1_COMPA_vect) +{ + PORTB ^= (1 << PB1); +} + +int main() +{ + DDRB = SPEAKER_PIN; + PORTB = BUTTON_PIN; + + TCCR1A = (0 << COM1A1) | (1 << COM1A0) | (0 << WGM11) | (0 << WGM10); + TCCR1B = (0 << WGM13) | (1 << WGM12) | (0 << CS12) | (1 << CS11) | (0 << CS10); + + TIMSK1 |= (1<