/* 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_SPK;
	Shield.sendData(CMD_SET, buf);
	flg--;
	} else {
	if (digitalRead(3)) {
	  rx_buf = Shield.receiveData();
	  if (rx_buf[1] == CMD_LED) {
	    switch (rx_buf[2]) {
	      case 49:
	        Shield.requestSPK(523, 500);
	        break;
	      case 50:
	        Shield.requestSPK(587, 500);
	        break;
	      case 51:
	        Shield.requestSPK(659, 500);
	        break;
	      case 52:
	        Shield.requestSPK(699, 500);
	        break;
	      case 53:
	        Shield.requestSPK(784, 500);
	        break;
		    }
		  }
		}
	delay(3);
	}
}