/* GR-SAKURA Sketch Template V2.13 */
#include <Arduino.h>
#include <SPI.h>
#include <RX231_Shield.h>

typedef unsigned char uint8_t;
RX231_Shield Shield = RX231_Shield();

unsigned char flg = 1;

void setup()
{
	Serial.begin(9600);
	Shield.begin();
}

void loop()
{
	uint8_t buf[14] = {0,};
	uint8_t * rx_buf;
	if (flg == 1) {
	  delay(500);
	  while(digitalRead(3)){
	    digitalWrite(2, 1);    
	    delay(5);
	    digitalWrite(2, 0);
	  }
	  delay(100);
	buf[0] = CMD_IRTX;
	Shield.sendData(CMD_SET, buf);
	flg--;
	} else {
	if (digitalRead(3)) {
	  rx_buf = Shield.receiveData();
	      if (rx_buf[1] == CMD_LED) {
	        Serial.print(rx_buf[2]);
	        Serial.println("  ON");
	        switch (rx_buf[2]) {
	          case 50:
	            Shield.requestIR(8, 8);
	            break;
	          case 51:
	            Shield.requestIR(8, 4);
	            break;
	          case 52:
	            Shield.requestIR(8, 1);
	            break;
	        }
	      }
		}
	delay(3);
	}
}