#include "P10Timers.h"
#include "UART0.h"
#include "song.h"
#include <avr/pgmspace.h>
uint32_t button_millis_check = 0;
uint8_t button_id = 0;
uint8_t checkButton ( void ) {
static uint8_t button_pressed = 0;
if ( PINF != 0x03) {
if (((PINF & 1) == 0)) {
button_id = 0;
}
if (((PINF & 2) == 0)) {
button_id = 1;
}
button_pressed ++;
button_millis_check = check_millis();
return -1;
}
if ( (button_pressed != 0) && ((check_millis() - button_millis_check) > 100)) {
button_pressed = 0;
return button_id;
}
return -1;
}
int main(void)
{
UART0_autobaudrate();
DDRH = (1 << PH6);
DDRF = 0x00;
PORTF = 0x03;
///no poner en 0, cancion nula
uint16_t song_index = 1;
uint8_t volume = 0;
Timer0_Ini();
while(1){
if (Timer2_Play( pgm_read_word(&song_list[song_index]), pgm_read_word(&song_list[song_index-1]))) {
if (song_index < 7) {
song_index++;
}
else {
song_index = 1;
}
}
//Increase Volume
if(UART_getchar() == 'V'){
Timer2_Volume(1);
}
//Decrease Volume
if(UART_getchar() == 'v'){
Timer2_Volume(-1);
}
switch (checkButton()){
case 0:
if (song_index <= 7){
song_index++;
}
else {
song_index = 1;
}
break;
case 1:
if (song_index > 1){
song_index--;
}
else {
song_index = 7;
}
break;
default:
asm("nop");
break;
}
}
return 0;
}