-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathattiny85-pacman.cpp
92 lines (78 loc) · 2.37 KB
/
attiny85-pacman.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "playtune.h"
#include "songs/mspacman-acti-they-meet-attiny.h"
#include "songs/mspacman-game-start-attiny.h"
#include "songs/mspacman-actii-the-chase-attiny.h"
#define output_low(port,pin) port &= ~(1<<pin)
#define output_high(port,pin) port |= (1<<pin)
#define output_toggle(port,pin) port ^= (1<<pin)
#define set_input(portdir,pin) portdir &= ~(1<<pin)
#define set_output(portdir,pin) portdir |= (1<<pin)
#define read_value(portdir,pin) ( portdir & (1<<pin) )
#define LED PB3
int main(void)
{
set_output(DDRB, LED);
output_low(PORTB, LED);
// setup interrupt
GIMSK |= (1<<INT0); // INT0 enabled for interrupts
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei();
while(1) {
output_low(PORTB, LED);
sleep_cpu();
}
return(0);
}
volatile uint8_t tune = 0;
ISR (INT0_vect)
{
output_high(PORTB, LED);
PlayTune theymeet0(0,MSPACMAN_ACTI_THEY_MEET0);
PlayTune theymeet1(1,MSPACMAN_ACTI_THEY_MEET1);
PlayTune gamestart0(0,MSPACMAN_GAME_START0);
PlayTune gamestart1(1,MSPACMAN_GAME_START1);
PlayTune thechase0(0,MSPACMAN_ACTII_THE_CHASE0);
PlayTune thechase1(1,MSPACMAN_ACTII_THE_CHASE1);
switch(tune) {
case 1:
while ( theymeet0.isPlaying() || theymeet1.isPlaying() ) {
theymeet0.playNote();
theymeet1.playNote();
_delay_ms(65);
}
break;
case 2:
while ( gamestart0.isPlaying() || gamestart1.isPlaying() ) {
gamestart0.playNote();
gamestart1.playNote();
_delay_ms(15);
}
break;
case 3:
while ( gamestart0.isPlaying() || gamestart1.isPlaying() ) {
gamestart0.playNote();
gamestart1.playNote();
_delay_ms(15);
}
break;
/*
while ( thechase0.isPlaying() || thechase1.isPlaying() ) {
thechase0.playNote();
thechase1.playNote();
_delay_ms(65);
}
break; */
}
if (tune == 3) {
tune = 1;
} else {
tune++;
}
}