ece312/lab_2/main.h
2019-10-19 22:15:38 -06:00

43 lines
862 B
C

#ifndef MAIN_H_
#define MAIN_H_
#define F_CPU 8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "notes.h"
#define TEMPO (120 * 4) // Tempo of song (bpm)
#define REST_FRACTION 0.3 // Fraction of the beat to stay silent between notes
#define BEAT_LENGTH 60000 / TEMPO // Length of each note (ms)
#define OCTAVES 2
#define NOTES_PER_OCTAVE 12
#define SPEAKER0_LEN 38
#define SPEAKER1_LEN 96
typedef enum {
a = 0, b, c, d, e, f, g,
A, C, D, F, G,
rest
} note_t;
typedef struct {
note_t note;
uint8_t duration:7;
uint8_t octave:1;
} beat_t;
extern const uint8_t PROGMEM notes[OCTAVES][NOTES_PER_OCTAVE];
extern const beat_t PROGMEM song_speaker0[SPEAKER0_LEN];
extern const beat_t PROGMEM song_speaker1[SPEAKER1_LEN];
void play_note(beat_t note, uint8_t speaker);
#endif