mirror of
https://github.com/alankrantas/microbit-micropython-cookbook.git
synced 2026-01-04 19:31:22 +01:00
Update README.md
This commit is contained in:
31
README.md
31
README.md
@@ -564,7 +564,7 @@ from microbit import display, Image, set_volume, sleep
|
|||||||
from micropython import const
|
from micropython import const
|
||||||
import music
|
import music
|
||||||
|
|
||||||
set_volume(128) # speaker volume (0-255)
|
set_volume(255) # speaker volume (0-255)
|
||||||
morse_delay = const(75) # morse code delay speed
|
morse_delay = const(75) # morse code delay speed
|
||||||
|
|
||||||
# morse code table
|
# morse code table
|
||||||
@@ -609,24 +609,23 @@ morse_code = {
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
print('Enter your message: (alphabets and numbers only)')
|
print('Enter your message: (Press enter to exit)')
|
||||||
msg_str = input('> ').upper()
|
msg_str = input('> ').upper()
|
||||||
print('Converting message...')
|
if not msg_str:
|
||||||
|
break
|
||||||
|
|
||||||
morse = []
|
morse_str = ''.join([morse_code[s] for s in msg_str
|
||||||
for s in msg_str:
|
if s in morse_code])
|
||||||
if s in morse_code:
|
print('Message converted:\n', morse_str)
|
||||||
for code in morse_code[s]:
|
|
||||||
morse.append(code)
|
for code in morse_str:
|
||||||
music.pitch(440)
|
music.pitch(440)
|
||||||
display.show(Image.TARGET)
|
display.show(Image.TARGET)
|
||||||
sleep(morse_delay * (3 if code == '-' else 1))
|
sleep(morse_delay * (3 if code == '-' else 1))
|
||||||
music.stop()
|
music.stop()
|
||||||
display.clear()
|
display.clear()
|
||||||
sleep(morse_delay)
|
sleep(morse_delay)
|
||||||
|
|
||||||
print('Message converted:')
|
|
||||||
print(''.join(morse))
|
|
||||||
print('')
|
print('')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user