// seta - Emisor de
infrarrojos //Código SIRCS de SONY //1-12-2011 //xsetaseta@gmail.com byte datos[20]; byte x; byte x1; byte comando; byte direccion; int xx; int xx1; void setup() { Serial.begin(9600); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(11, INPUT); pinMode(12, INPUT); //devolver codigo pinMode(9, OUTPUT); pinMode(10, OUTPUT); // Clear Timer on Compare Match (CTC) Mode bitWrite(TCCR1A, WGM10, 0); bitWrite(TCCR1A, WGM11, 0); bitWrite(TCCR1B, WGM12, 1); bitWrite(TCCR1B, WGM13, 0); // Toggle OC1A and OC1B on Compare Match. bitWrite(TCCR1A, COM1A0, 1); bitWrite(TCCR1A, COM1A1, 0); bitWrite(TCCR1A, COM1B0, 1); bitWrite(TCCR1A, COM1B1, 0); // No prescaling bitWrite(TCCR1B, CS10, 1); bitWrite(TCCR1B, CS11, 0); bitWrite(TCCR1B, CS12, 0); OCR1A = 200; // 40KHz OCR1B = 200; } void loop() { if (digitalRead(12)==LOW) { x=WriteIR(18,1); //repetición de 3 veces el dato delay(24); x=WriteIR(18,1); delay(24); x=WriteIR(18,1); delay(100); } } int WriteIR(byte com,byte dir) { digitalWrite(3, HIGH); digitalWrite(2, HIGH); for(xx=0;xx<5500;xx++); digitalWrite(2, LOW); for(x=0;x<7;x++) { for(xx=0;xx<1375;xx++); digitalWrite(2, HIGH); if(com & 1) for(xx=0;xx<2750;xx++); else for(xx=0;xx<1375;xx++); digitalWrite(2, LOW); com = (com >> 1); } for(x=0;x<5;x++) { for(xx=0;xx<1375;xx++); digitalWrite(2, HIGH); if(dir & 1) for(xx=0;xx<2750;xx++); else for(xx=0;xx<1375;xx++); digitalWrite(2, LOW); dir = (dir >> 1); } digitalWrite(3, LOW); } |