Example #1
0
void loop(void) {
  uint16_t highpulse, lowpulse;  // temporary storage timing
  highpulse = lowpulse = 0; // start out with no pulse length


  //  while (digitalRead(IRpin)) { // this is too slow!
  while (IRpin_PIN & (1 << IRpin)) {
    // pin is still HIGH

    // count off another few microseconds
    highpulse++;
    delayMicroseconds(RESOLUTION);

    // If the pulse is too long, we 'timed out' - either nothing
    // was received or the code is finished, so print what
    // we've grabbed so far, and then reset
    if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
      printpulses();
      currentpulse=0;
      return;
    }
  }
  // we didn't time out so lets stash the reading
  pulses[currentpulse][0] = highpulse;

  // same as above
  while (! (IRpin_PIN & _BV(IRpin))) {
    // pin is still LOW
    lowpulse++;
    delayMicroseconds(RESOLUTION);
    if ((lowpulse >= MAXPULSE)  && (currentpulse != 0)) {
      printpulses();
      currentpulse=0;
      return;
    }
  }
  pulses[currentpulse][1] = lowpulse;

  // we read one high-low pulse successfully, continue!
  currentpulse++;
}
void loop(void)
{	
	// Read the state of the "Send" push-button value
	buttonState1 = digitalRead(buttonPin1);
	// Read the state of the "Receive" push-button value
	buttonState2 = digitalRead(buttonPin2);

	if (buttonState1 == HIGH) {
		  
		std::cout << "Sending IR signal" << std::endl;
		digitalWrite(orangeLedPin, HIGH); 
		delay(200);
		digitalWrite(orangeLedPin, LOW); 
		delay(200);
		
		SendIRCode();
		delay(15);  // wait 15 milliseconds before sending it again
		SendIRCode();  // repeat IR code if it is neccesary
	 
		//delay(3000);  // wait 3 seconds to resend the code
    }

	if ((buttonState2==HIGH) || (currentpulse != 0)){

	if (buttonState2==HIGH){
		std::cout << "Ready to decode IR!" << std::endl;
		digitalWrite(blueLedPin, HIGH); 
		delay(200);
		digitalWrite(blueLedPin, LOW); 
		delay(200);
	}

	uint16_t highpulse, lowpulse; // Temporary storage timing
	highpulse = lowpulse = 0; // Start out with no pulse length

	while (digitalRead(IRpin)) {
		// count off another few microseconds
		highpulse++;
		delayMicroseconds(RESOLUTION);

		// If the pulse is too long, we 'timed out' - either nothing
		// was received or the code is finished, so print what
		// we've grabbed so far, and then reset
		if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
			printpulses();
			sendpulse=currentpulse;
			currentpulse=0;
			return;
		}
	}
	// we didn't time out so lets stash the reading
	pulses[currentpulse][0] = highpulse;

	// same as above
	while (! digitalRead(IRpin)) {
		// pin is still LOW
		lowpulse++;
		delayMicroseconds(RESOLUTION);
		if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
			printpulses();
			sendpulse=currentpulse;
			currentpulse=0;
			return;
		}
	}
	pulses[currentpulse][1] = lowpulse;

	// we read one high-low pulse successfully, continue!
	currentpulse++;

	}
}