Morsecode Library

morsecode

Circuitpython library to crete Morse code

  • Author(s): Jose David M.

Implementation Notes

Software and Dependencies:

class morsecode.Emitter(pin)

Creates a Receiver object ex: sreceptor = Emmiter(‘D13’)

Quickstart: Importing and using the Emitter

Here is an example of using the Emitter class. First you will need to import the libraries to use it

from mc_emitter import Emitter
import board

Once this is done you can define your morse code Emitter

internal_led = Emitter(board.D13)

Now you could send phrases to the emitter like so:

internal_led.outmorse("Hugo AKA the Architect")
blinking(blinktime: int)
Parameters:

blinktime (int) – duration in seconds

Returns:

None

convertbpm(bpm)

Converts beats per minute in light output

Parameters:

bpm (int) – Beats per minute

Returns:

None

convertphrase(phrase: str) List[str]

Convert a phrase to a list of words converted to morse code. We use a list to allow the library do some threading methods

Parameters:

phrase – string to be converted to morse code

Returns:

list of words converted to morse code

convertword(word: str) str

Convert a word to its representation in morse code

Parameters:

word – word string

Returns:

string of morse code

static convletter(letter: str, final: str) str

Converts a letter to its representation in morse code

Parameters:
  • letter (str) – Letter to be converted

  • final (str) – Final character encoding

Returns:

string representation in morse code

flashing(ontime: float, offtime: float, repeat: int)

Flash the led according to given parameters

Parameters:
  • ontime (float) – time in seconds for the Emitter to be ON

  • offtime (float) – time in seconds for the Emitter to be OFF

  • repeat (int) – number of repetitions

Returns:

None

outmorse(phrase: str, duration: float = 0.1) None

Plays the morse code

Parameters:
  • phrase (str) –

  • duration (float) – This value hods the logic of the morse code wpm(words per minute) In this case we use 0.1 that means that we use 120/0.12

Returns:

None

pattern(patternl: List[int]) None

Converts a list of values [0 or 1] to an output in the Emitter

Parameters:

patternl (list) – list of [0-1] values

Returns:

None

led = Emitter('D2')
codigo = [1,1,0,1,0,0,1,1,1,0,0,1,1,1,1,1,0,0,0,1]
led.pattern(codigo)

Emits a random output to the Emitter

Parameters:

iterl (int) – number of values to be randomly generated

Returns:

None

turnoff(pausa: float = 0.1)

Turns off the Emitter

Parameters:

pausa (float) – time in seconds for the Emitter to be OFF

Returns:

None

turnon(pausa: float = 0.1)

Turns on the Emitter :param float pausa: time in seconds for the Emitter to be ON :return: None