Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Mar 13, 2018. It is now read-only.
raspberrypilearning
/
morse-code-virtual-radio
Public archive
Notifications
You must be signed in to change notification settings
Fork
13
Star
45
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
morse-code-virtual-radio
/
code
/
final_code.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
executable file
·
72 lines (61 loc) · 1.99 KB
master
Breadcrumbs
morse-code-virtual-radio
/
code
/
final_code.py
Copy path
Top
File metadata and controls
Code
Blame
executable file
·
72 lines (61 loc) · 1.99 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3
import pygame
import time
import gpiozero as gpio
import _thread as thread
from array import array
from pygame.locals import *
from morse_lookup import *
pygame.mixer.pre_init(44100, -16, 1, 1024)
pygame.init()
class ToneSound(pygame.mixer.Sound):
def __init__(self, frequency, volume):
self.frequency = frequency
pygame.mixer.Sound.__init__(self, self.build_samples())
self.set_volume(volume)
def build_samples(self):
period = int(round(pygame.mixer.get_init()[0] / self.frequency))
samples = array("h", [0] * period)
amplitude = 2 ** (abs(pygame.mixer.get_init()[1]) - 1) - 1
for time in range(period):
if time < period / 2:
samples[time] = amplitude
else:
samples[time] = -amplitude
return samples
def decoder_thread():
global key_up_time
global buffer
new_word = False
while True:
time.sleep(.01)
key_up_length = time.time() - key_up_time
if len(buffer) > 0 and key_up_length >= 1.5:
new_word = True
bit_string = "".join(buffer)
try_decode(bit_string)
del buffer[:]
elif new_word and key_up_length >= 4.5:
new_word = False
sys.stdout.write(" ")
sys.stdout.flush()
tone_obj = ToneSound(frequency = 800, volume = .5)
pin = 4
key = gpio.Button(pin, pull_up=True)
DOT = "."
DASH = "-"
key_down_time = 0
key_down_length = 0
key_up_time = 0
buffer = []
thread.start_new_thread(decoder_thread, ())
print("Ready")
while True:
key.wait_for_press()
key_down_time = time.time() #record the time when the key went down
tone_obj.play(-1) #the -1 means to loop the sound
key.wait_for_release()
key_up_time = time.time() #record the time when the key was released
key_down_length = key_up_time - key_down_time #get the length of time it was held down for
tone_obj.stop()
buffer.append(DASH if key_down_length > 0.15 else DOT)
You can’t perform that action at this time.