diff --git a/decode_message_3.py b/decode_message_3.py index 980ffd3..3071de1 100644 --- a/decode_message_3.py +++ b/decode_message_3.py @@ -4,6 +4,7 @@ CLOCK_CHANNEL = 16 DATA_CHANNEL = 23 + # This is a callback function that will be called whenever we have a high/low # or low/high change in the signal. def my_callback(channel): @@ -20,6 +21,7 @@ def my_callback(channel): my_callback.counter = 0 my_callback.result_byte = 0 + my_callback.counter = 0 my_callback.result_byte = 0 diff --git a/encode_message.py b/encode_message.py index 5d8d4e0..955de61 100644 --- a/encode_message.py +++ b/encode_message.py @@ -28,9 +28,17 @@ # significant bit 7, down to 0. for bit_pos in range(bits_in_a_byte - 1, -1, -1): + # Next line is complicated. # Use a single 1, and bit shift it with << to the - # spot we are interested in. Then use a bitwise - # and to see if that spot has a value + # spot we are interested in. Then use a bitwise and (&) + # and to see if that spot has a value. + # if bit pos = 6 then + # 1 << 6 = 0100 0000 = 64 + # if my_byte = 'H' which ASCII 72 = 0100 1000 binary + # H = 0100 1000 + # 1 << 6 = 0100 0000 + # --------- + # & = 0100 0000 = 64 (result of bit-wise 'and') bit = (1 << bit_pos) & my_byte if bit != 0: