Let’s put ease of expanding the application to the test by adding a feature. Instead of just counting down seconds, the expanded application will ask you for the millisecond (ms) time between counts. You can still choose 1000 to have it count in seconds, but you can also specify a value like 100 to have it count in tenths of seconds.
Sender changes for countdown_sender
text = input("Enter countdown start: ") value = int(text) text = input("Enter ms time between counts: ") # add ms = int(text) # add message = input("Enter message after countdown: ") dictionary = { } dictionary['start'] = value dictionary['time'] = ms # add dictionary['after'] = message
Receiver Changes for countdown_receiver
value = dictionary['start'] ms = dictionary['time'] # add message = dictionary['after'] print("value = ", value) print("ms = ", ms) # add print("message = ", message, "\n") while value >= 0: print(value) sleep(ms) # change value = value - 1
Only one line had to be added to the sender to send the ms value, and another to the receiver to recover it. The rest of the changes would have been made, even if it was just one script on a single micro:bit.