Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Author: Montaj Pennant
- //Title: Homework4
- #define LA 0x8E0B
- #define LAS 0x8612
- #define LB 0x7E8C
- #define LC 0x7772
- #define LCS 0x70BD
- #define LD 0x6A69
- #define LDS 6470
- #define LE 0x5ECD
- #define LF 0x597B
- #define LFS 0x5475
- #define LG 0x4FB8
- #define LGS 0x4B3E
- #define MA 0x4705
- #define MAS 0x4309
- #define MB 0x3F46
- #define MC 0x3BB9
- #define MC# 0x385E
- #define MD 0x3534
- #define MDS 0x3238
- #define ME 0x2F66
- #define MF 0x2CBD
- #define MFS 0x2A3A
- #define MG 0x27DC
- #define MGS 0x259F
- #define HA 0x2382
- //define the length of each note (in milliseconds)
- #define DOTTED_HALF 750
- #define QUARTER 250
- #define HALF 500
- #define WHOLE 1000
- #define delayTime 50 //post-note delay to avoid perceived overlap of notes (in milliseconds)
- void setup() {
- //Best Practice: Clear TCCR registers before setting-up
- TCCR1A &= 0;
- TCCR1B &= 0;
- DDRB = 0x0F; //sets PB3-PB0 as outputs
- }
- void loop() {
- playNote(MB, QUARTER);
- playNote(MA, QUARTER);
- playNote(LG, QUARTER);
- playNote(MA, QUARTER);
- playNote(MB, QUARTER);
- playNote(MB, QUARTER);
- playNote(MB, HALF);
- playNote(MA, QUARTER);
- playNote(MA, QUARTER);
- playNote(MA, HALF);
- playNote(MB, QUARTER);
- playNote(MD, QUARTER);
- playNote(MD, HALF);
- playNote(MB, QUARTER);
- playNote(MA, QUARTER);
- playNote(LG, QUARTER);
- playNote(MA, QUARTER);
- playNote(MB, QUARTER);
- playNote(MB, QUARTER);
- playNote(MB, QUARTER);
- playNote(MB, QUARTER);
- playNote(MA, QUARTER);
- playNote(MA, QUARTER);
- playNote(MB, QUARTER);
- playNote(MA, QUARTER);
- playNote(LG, WHOLE);
- }
- void playNote(int max_count, int note_size) {
- TCCR1A |= 0x40; //Sets Timer 1 Channel A to toggle on Compare Match
- TCCR1B |= 0x09; //Sets Timer 1 to CTC mode
- OCR1A = max_count; //sets the period of the given note as the toggle point for Timer 1 Channel A
- delay(note_size);
- TCCR1B |= 0x08; //Turn off Timer 1's connection to the system clock
- delay(delayTime);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement