/* 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_MPU;
	Shield.sendData(CMD_SET, buf);
	flg--;
	} else {
	if (digitalRead(3)) {
	  rx_buf = Shield.receiveData();
	      if (rx_buf[1] == CMD_LED) {
	        if (rx_buf[2] == 54) {
	          Shield.requestMPU();
	        }
	        Serial.print(rx_buf[2]);
	        Serial.println("  ON");
	      }else if(rx_buf[1] == CMD_MPU){
	        for(int i = 2 ; i < 16 ; i++){
	          Serial.print(rx_buf[i]);
	          Serial.print("  ");
	        }
	        Serial.println();
	      }
		}
	delay(3);
	}
}