Looks like 7 LOW bits, 1 HIGH bit, and 6 bits of data. Or possibly 7 LOW bits and 7 bits of data.
You should get
7F (1111111) if there is a timeout.
49 (1001001) for the red oval button
6E (1101110) for the grey oval button
5B (1011011) for the grey round button
const byte CommPin = 4; // Pick a data pin
byte Receive()
{
byte value = 0;
unsigned long waitStart = millis();
// Wait for the pin to go low or a timeout
while (digitalRead(CommPin) == HIGH &&
millis() - waitStart < 5000) {};
// Since the non-delay() code takes some
// time, we aim to start sampling a little
// before the cengter of the 8th bit.
delay(74);
for (int i = 0; i < 7; i++)
{
value <<= 1;
value += digitalRead(CommPin);
delay(10);
}
return value;
}
void Send(byte value)
{
// Send the 70ms of LOW
pinMode(CommPin, OUTPUT);
delay(70);
for (int i = 6; i >= 0; i--)
{
if (value & _BV(i))
pinMode(CommPin, INPUT); // HIGH
else
pinMode(CommPin, OUTPUT); // LOW
delay(10);
}
pinMode(CommPin, INPUT); // idle HIGH
}
void setup()
{
Serial.begin(115200);
delay(200);
pinMode(CommPin, INPUT);
digitalWrite(CommPin, LOW);
}
void loop()
{
Serial.println(Receive(), HEX);
}