Decoder -----__---___----_________ | | | | | look for start when start found calculate next sample time, reset bit count have a function called sample(ip,dt); sample( ip,dt ) switch state WAITING_FOR_EDGE: edge = ~ip and lastIp lastIp = ip; if ( edge ){ reset time, reset serial reset count nextsampletime = 1.5*baud state = WAITING_FOR_NEXT_SAMPLE } WAITING_FOR_NEXT_SAMPLE: time += dt if ( time > next sample ){ // sample input serial = serial * 2 + ip count ++ if (count > 8) { emit serial state = WAITING_FOR_NEXT_SAMPLE } // time = time - nextSample