Тема: IRemote
bool data[96];
unsigned long cod;
int i,i2;
void setup() {
Serial.begin(9600);
DDRB &= ~(1 << 0);
cli();
TCCR1A = 0;
TCCR1B = 0;
OCR1A = 9000; // 562.5 mks
TCCR1B |= (1 << WGM12);
TCCR1B &= ~(1 << CS10);
TIMSK1 |= (1 << OCIE1A);
sei();
}
void loop() {
Serial.println(IR(),HEX);
// delay(100);
}
uint32_t IR(){
while(PINB & (1 << 0));
delay(10);
while(PINB & (1 << 0));
TCCR1B |= (1 << CS10);
delayMicroseconds(100);
delay(136);
cod=0;i2=0;
for(int a=0;a<96;a++){
if(data[a] + data[a+2] == 2){cod += ((uint32_t)0 << 31-i2);i2++;a=a+1;}
if(data[a] + data[a+2] == 1){cod += ((uint32_t)1 << 31-i2);i2++;a=a+3;}}
return cod;
}
ISR(TIMER1_COMPA_vect){
data[i]=((PINB >> 0) & 1);i++;
if(i>96){TCCR1B &= ~(1 << CS10);i=0;}
}