#include "m32.h"
#include "avr/io.h"
#include "avr/pgmspace.h"
#include "avr/interrupt.h"
#include "stdlib.h"
#include "string.h"
#include "uart.h"

static char blink = 1;			//blinking flag

void main()
{
	initStuff();			//initialise port, and interrupts
	blink();			//blink forever
}

void
initStuff()
{
//DDRA - 1 output,  0 input
//PORT - 1 digital, 0 analogue

//0 output blue
//1 input button 	-  when released - rising 	-  int0
//2 input ir 		- 'falling edge'  		-  int1
//3 output red
//4 output green
//5 output yellow
//6 -
//7-




	//port d
	DDRD  = BIN(00111001);
	PORTD = BIN(11111111);

	MCUCR	= BIN(00001011);	//int0 - 3 - rising, int1 - 2 falling
	GICR	= BIN(11000000);	//enable int0,int1;
	sei();


}



SIGNAL(INT0_vect)			//input button, rising edge
{
	blink =1;
}

SIGNAL(INT1_vect)			//ir reciever, falling edge
{
	if (blink)
	{
		Printf("IR SIGNAL DETECTED");
		blink = 0;
	}
}


void
blink()
{		
	//		      /--------------	yellow
	//		      |/------------	green
	//		      ||/-----------	red
	//		      |||  /--------	blue
	//		      |||  |
	char signal[4];//     |||  |
	signal[0] = 	BIN(11001110);//red
	signal[1] = 	BIN(11010110);//green
	signal[2] = 	BIN(11000111);//blue
	signal[3] = 	BIN(11100110);//yellow
	char i;

	signal[0]
	while (1)
	{
		if(blink)
		{
			i++;
			if (i==4)
				i=0;
			PORTD = signal[i];		//blink (at a stupid number of Hz, not visible to eye, but still blinking)
		}
	}
}


//c because the portD lines 0 and 1 are used for the blue led and the switch,
//the transmit and recieve signals of the UART cannot be fed from the RS232,
//since that is how the printf function works on this microcontroller, it aint gonna work.
