Skip to content

Instantly share code, notes, and snippets.

@emwdx
Created May 13, 2022 05:38
Show Gist options
  • Save emwdx/fbea45d647426ae403941e3a1c10c8e7 to your computer and use it in GitHub Desktop.
Save emwdx/fbea45d647426ae403941e3a1c10c8e7 to your computer and use it in GitHub Desktop.
Circuitpython Morse Code Receiver
import time
import board
from adafruit_circuitplayground import cp
import digitalio
from analogio import AnalogIn
inputPin = cp.light
THRESHOLD = 2000
DELAY_SECONDS = 0.005
TOTAL_RECORD_TIME = 10.0
elapsedTime = 0.0
oldTime = time.monotonic()
data = []
def thresholdValue(value):
if(value > THRESHOLD):
return 1
else:
return 0
while (elapsedTime < TOTAL_RECORD_TIME):
currentTime = time.monotonic()
pinValue = cp.light
recordValue = pinValue#thresholdValue(pinValue)
#print("{0},{1}".format(elapsedTime, recordValue))
data.append([elapsedTime,recordValue])
time.sleep(DELAY_SECONDS)
elapsedTime += currentTime - oldTime
oldTime = currentTime
for row in data:
print("{0},{1}".format(row[0], row[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment