335#include <util/delay.h>
357#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
465 printString(
"Controls: a-s-d-f-g-h-j-k-l-;-' for white keys\r\n");
467 printString(
" 1 to play Twinkle Twinkle Little Star\r\n");
468 printString(
" 2 to play Imperial March from Star Wars\r\n");
469 printString(
" '[' = short note (250ms), ']' = long note (500ms)\r\n");
490 const uint8_t keys[] = {
'a',
'w',
's',
'e',
'd',
'f',
't',
491 'g',
'y',
'h',
'j',
'i',
'k',
'o',
492 'l',
'p',
';',
'\''};
518 if (receivedChar == keys[i])
534 if (receivedChar ==
'[')
540 else if (receivedChar ==
']')
546 else if (receivedChar ==
'1')
550 printString(
"\r\nPlaying Twinkle Twinkle Little Star\r\n");
552 else if (receivedChar ==
'2')
555 printString(
"\r\nPlaying Imperial March from Star Wars\r\n");
567 if (receivedChar !=
'\r' && receivedChar !=
'\n')
CPU configuration and definitions for ATmega168.
USART serial communication interface.
void initUSART(void)
Initializes the USART peripheral for serial communication.
uint8_t receiveByte(void)
Receives a single byte from USART.
void printString(const char String[])
Sends a null-terminated string over USART.
void transmitByte(uint8_t data)
Transmits a single byte over USART.
#define BUZZER_DDR
Data Direction Register for BUZZER pin.
#define BUZZER_PIN
BUZZER pin number within its port.
#define ARRAY_SIZE(x)
Calculate the number of elements in a static array at compile time.
uint16_t currentNoteLength
Current note duration in milliseconds.
int main(void)
Main program entry point.
const uint16_t notes[]
Array of musical notes mapped to keyboard keys.
Organ tone generator interface.
void playNote(uint16_t half_us, uint16_t duration_ms)
Play a musical tone.
void rest(uint16_t duration_ms)
Hardware pin mapping for BUZZER/buzzer output.
Pre-defined songs for musical organ.
void play_imperial_march()
Plays "Imperial March" (Darth Vader's Theme) from Star Wars.
void play_twinkle_little_star()
Plays "Twinkle Twinkle Little Star" melody.
Musical note frequency lookup table (16-bit timer values)