Rechnerarchitektur/Aufgabe_3_1_2/sketch_nov3a/sketch_nov3a.ino

91 lines
2.3 KiB
Arduino
Raw Permalink Normal View History

2023-11-27 16:42:21 +00:00
#include <avr/io.h> /* Hardware-Definitionen */
#include <util/delay.h>
#include <stdint.h> /* 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<<i);
PORTD |= (1<<i); /* LED an */
_delay_ms(250); /* 500ms warten */
PORTD &= ~(1<<i); /* LED aus */
_delay_ms(250); /* 500ms warten */
i++;
if(i == 6) {
i = 2;
pressed = false;
}
}
}
return 0;
}