#include <avr/io.h>

void secDelay(int count){
	int i;
	for(;count>0;count--){
		for(i=1000; i>0;i--){
			i--;
		}	
	}
}

void tenthSecDelay(int count){
	int i;
	for (;count>0; count--){
		for(i=100; i>0;i--){
			i--;
		}	
	}
}

int main(){
	DDRD	= 0x00; // make D all input; adjusts wait until power-on
	DDRB    = 0xC0; // 1100 0000; makes PB7, PB6 output and the rest input

	while (1) {
		PORTB = 0x80; // 1000 0000; makes PB7 = !Q = On, PB6 = Q = Off
//		float secsDelay = PORTD / 10; // loses decimal due to flooring
//		float tenthDelay = PORTD / 10 - secsDelay; // just the tenths
		int secsDelay = PORTD;
		int tenthDelay = PORTD - secsDelay;
	
//		int secsOn = PORTB / 10;
		int secsOn = PORTB;
//		float tenthsOn = PORTB / 10 - secsOn;
		float tenthsOn = PORTB - secsOn;

		secDelay(secsDelay);
		tenthSecDelay(tenthDelay);

		if (!((secsOn == 0) && (tenthsOn == 0))) {
			// PB6 is Q, PB7 is !Q
			PORTB = 0x40; // 0100 0000
			secDelay(secsOn);
			tenthSecDelay(tenthsOn);
		} else {
			PORTB = 0x40; // must be infinitely on
			break; // goes to next infinite while which is dead
		}
	}

	while (1) { }

	return 0;
}

