+ while(1)
+ {
+ ADCSRA |= (1 << ADSC); // start ADC measurement
+ while (ADCSRA & (1 << ADSC) ); // wait till conversion complete
+ {
+ // We are detecting "video" if we have a value
+ // greater than some minimal value on ADC1/PB2.
+ // This approach requires a weak pulldown on the relevant
+ // video input to the circuit, but it beats not detecting anything.
+ // 255/50*4=20, thus 0.4V
+ if (ADCH > 20)
+ {
+ // Make sure any signal generated by us does not leak back
+ PORTB &= 0xEF; // Switch OFF VOut-switch for ATtiny
+ // The next statement stops sync-generation, thus also image-generation..
+ TIMSK &= ~(1<<OCIE0A); // Enable compare-mach-a interrupt
+ // Reset Timer1 so we don't generate a TOVF..
+ TCNT1 = 0;
+ }
+ // If we did not see a signal above the treshold, TCNT1 will continue
+ // to count up, until a TOV1 interrupt is generated.
+ }
+ };