Stroposkop

#include <avr/io.h>
#include <avr/interrupt.h>
//#include <util/delay.h>

//Timerdurchlauf 0,075ms ( Angaben in halben ms)

#define strop_time_min 500
#define strop_time_max 8000
#define LED_PIN (1<<4)


//Variablen
unsigned int volatile strop, strop_ct, flash_ct ,flash_flag,flash,keep_on,strop_flag,rd_adc;


//Hauptschleife

int main(void)
{       

  ADMUX = 0x02;
  ADCSRA = 0xc5;
 TCCR0B = 0x01;
TIMSK0 |= (1 << TOIE0);
  sei();
  
  
  DDRB |= LED_PIN;
  
  strop = strop_time_min;
  strop_ct = 0;
  flash_ct = 0;
  flash_flag = 0;
  strop_flag=1;
  keep_on = 0;
  
 
   while(1)
   { 
     
 //Stropzeit einlesen
       ADMUX = 0x03;
       ADCSRA |= (1<<ADSC);
  

	   
	   
	   while (ADCSRA & (1<<ADSC) );
	   {
	     
	   }

		strop = (((strop_time_max-strop_time_min)/1024)*ADCW)+strop_time_min;	
		
		if (strop < strop_time_min)
		{
		strop = strop_time_min;
		}
		
		if (ADCW > 1000)
		{
		keep_on = 1;
		}
		else
		{
		keep_on = 0;
		}
		
//Flash Zeit einlesen
		ADMUX = 0x01;
       ADCSRA |= (1<<ADSC);
     
	   
	   while (ADCSRA & (1<<ADSC) );
	   {
	     
	   }
		flash = ADCW/2;	
		
   }
}


// Timer Überlauf

SIGNAL (SIG_OVERFLOW0)
{

  TCNT0 = 200;

  strop_ct++;
  flash_ct++;
  rd_adc++;
  
  if (strop_flag == 1)
  {
  		if (strop_ct >= strop)
		//Blitz
		{
			flash_flag = 1;
			strop_flag = 0;
			flash_ct = 0;
		}  
	}
		
		if (flash_flag == 1)
		{
		PORTB |= LED_PIN;
		
			if (flash_ct <= flash)
			{
			PORTB |= LED_PIN;
			}
			else
			{
			flash_flag = 0;
				if (keep_on == 0)
				{
				PORTB &= ~(LED_PIN);
				}
			strop_ct = 0;
			strop_flag = 1;
			}
		
		}
 
}