/*
* LED_fading_03.c
* Controller: ATmega88 @ 8MHz
*/
#include <avr/io.h>
#include <util/delay.h>
#include 		// Einbinden der Headerdatei math.h für mathematische Funktionen

int main(void)
{
	DDRB |= (1<<PB1);	// OC1A = output
	ICR1 = 65535;		// ICR1 = Top Value
	
	// Mode 10: PWM, Phase Correct, Prescaler = 1, Clear OC1A on compare match
	TCCR1A = (1 << COM1A1) + (1 << WGM11);
	TCCR1B = (1 << WGM13) + (1 << CS10);
	
	while(1)
	{
		float result;						// Datentyp float für Gleitkommaberechnungen
		uint8_t basis = 80, steps = 72;		// Basiswert und steps ausprobieren
		
		for(uint8_t i=0; i<= 254; i++)
		{
			result = ((pow(basis,(float)i/100))/(basis-1))*steps;	// Typecast i
			OCR1A = (uint16_t)result;		// Typecast result
			_delay_ms(100);
		}
		
		for(uint8_t i=255; i>= 1; i--)
		{
			result = ((pow(basis,(float)i/100))/(basis-1))*steps;	// Typecast i
			OCR1A = (uint16_t)result;		// Typecast result
			_delay_ms(100);
		}
	}
}