65 lines
1.7 KiB
Arduino
65 lines
1.7 KiB
Arduino
|
/*
|
||
|
PSConSPI
|
||
|
(c)2011 kou029w - MIT License [http://kou029w.appspot.com/mit-license.txt]
|
||
|
|
||
|
PSCon Arduino
|
||
|
CLK 13 SCK
|
||
|
SEL 10 SS
|
||
|
CMD 11 MOSI
|
||
|
DAT 12 MISO
|
||
|
*/
|
||
|
|
||
|
#include <SPI.h>
|
||
|
|
||
|
void get(byte data[8]){
|
||
|
digitalWrite(10, LOW);
|
||
|
SPI.transfer(0x01);
|
||
|
for(byte i=0; i<8; i++){
|
||
|
data[i] = SPI.transfer(data[i]);
|
||
|
}
|
||
|
digitalWrite(10, HIGH);
|
||
|
}
|
||
|
|
||
|
void setup(){
|
||
|
SPI.setBitOrder(LSBFIRST);
|
||
|
SPI.setDataMode(SPI_MODE3);
|
||
|
SPI.setClockDivider(SPI_CLOCK_DIV128);
|
||
|
SPI.begin();
|
||
|
Serial.begin(9600);
|
||
|
}
|
||
|
|
||
|
void loop(){
|
||
|
byte data[] = {0x42,0,0,0,0,0,0,0};
|
||
|
get(data);
|
||
|
if(data[0] == 0x73){ // デジコン:0x41, アナコン:0x73
|
||
|
Serial.print("R(x,y):(");
|
||
|
Serial.print(data[4], DEC); // 上が0x00, 下が0xFF
|
||
|
Serial.print(",");
|
||
|
Serial.print(data[5], DEC); // 左が0x00, 右が0xFF
|
||
|
Serial.print(") ");
|
||
|
Serial.print("L(x,y):(");
|
||
|
Serial.print(data[6], DEC); // 上が0x00, 下が0xFF
|
||
|
Serial.print(",");
|
||
|
Serial.print(data[7], DEC); // 左が0x00, 右が0xFF
|
||
|
Serial.print(") ");
|
||
|
}
|
||
|
if(~data[2] & 0x01<<0)Serial.print("sel ");
|
||
|
if(~data[2] & 0x01<<1)Serial.print("L3 ");
|
||
|
if(~data[2] & 0x01<<2)Serial.print("R3 ");
|
||
|
if(~data[2] & 0x01<<3)Serial.print("sta ");
|
||
|
if(~data[2] & 0x01<<4)Serial.print("^ ");
|
||
|
if(~data[2] & 0x01<<5)Serial.print("> ");
|
||
|
if(~data[2] & 0x01<<6)Serial.print("v ");
|
||
|
if(~data[2] & 0x01<<7)Serial.print("< ");
|
||
|
if(~data[3] & 0x01<<0)Serial.print("L2 ");
|
||
|
if(~data[3] & 0x01<<1)Serial.print("R2 ");
|
||
|
if(~data[3] & 0x01<<2)Serial.print("L1 ");
|
||
|
if(~data[3] & 0x01<<3)Serial.print("R1 ");
|
||
|
if(~data[3] & 0x01<<4)Serial.print("% ");
|
||
|
if(~data[3] & 0x01<<5)Serial.print("O ");
|
||
|
if(~data[3] & 0x01<<6)Serial.print("X ");
|
||
|
if(~data[3] & 0x01<<7)Serial.print("# ");
|
||
|
Serial.println();
|
||
|
delay(16);
|
||
|
}
|