#define RXD 4 #define TXD 3 #define CLK 2 #define WAIT 500 char no = 0; uint8_t receive; void setup() { pinMode(TXD, OUTPUT); pinMode(RXD, INPUT); pinMode(CLK, OUTPUT); digitalWrite(CLK, LOW); Serial.begin(19200); //ノイズ対策(?)のため7bit送る for(int i=0; i<7; i++) { digitalWrite(TXD, HIGH); delay(10); digitalWrite(CLK, HIGH); delay(10); digitalWrite(CLK, LOW); } } void loop() { sendByte(no); Serial.print(receive, HEX); Serial.print(" "); if(++no == 255) no = 0; } void sendByte(byte b) { uint8_t onebit; receive = 0; for(int i=0; i<8; i++) { onebit = (b >> (7 - i)) & 1; digitalWrite(TXD, onebit); delayMicroseconds(WAIT); digitalWrite(CLK, HIGH); delayMicroseconds(WAIT); receive += (digitalRead(RXD) << (7 - i)); digitalWrite(CLK, LOW); } }