Challenge Lesson - Ozobot Bit Morse Code Generator · what has become known as the Morse code,...

Preview:

Citation preview

Ozobot Bit Morse Code Generator

Created by

Richard Born

Associate Professor Emeritus

Northern Illinois University

richb@rborn.org

Topics

Computer Science, Functions,

Visual block programming

Ages

Grades 9-12

Duration Intended as a homework assignment; 1-2 hours

OZO

BOT STREA

M

APPROVED

APPROVED

1

Challenge Lesson:

Ozobot Bit Morse Code Generator

By Richard Born Associate Professor Emeritus

Northern Illinois University rborn@niu.edu

Introduction

MosteveryonehasheardoftheinternationaldistresssignalSOS,“SaveOurSouls”:

WiththelettersSandOencodedasaseriesofdots(dit)anddashes(dah),thissignalmakesuseofwhathasbecomeknownastheMorsecode,namedafterSamuelMorse,inventoroftheland-linetelegraphsystembackin1837.SOSisjustoneofmanyabbreviationsusingMorsecodethatareunderstoodinternationally,makingMorsecodeindependentofproficiencyintheEnglishlanguage.

Morsecodehasanumberofuseseventothisday.ItispopularamongamateurradiooperatorsbutisnolongerrequiredforlicensingintheUnitedStatesandmanyothercountries.Itisusedinthemedicalsciencesasanassistivecommunicationtechnologyforpeoplewithseveredisabilities,suchasbeingbothdeafandblind.Amessagethatcanbereadbycomputersistappedorblinkedoutbythepersonwiththedisability.SkinbuzzerscanthenbeusedtoreceiveMorsecodes.TheabilitytosenddistressmessagesoverlargedistancewithrelativelylowpowerrequirementshasmadeMorsecodeusefulinthemilitary.

Morsecodehasseveraladvantagesinadditiontothosesuggestedinthepreviousparagraph.Morsecodecanbereadbyskilledlistenerswithouttheneedforadecodingdeviceofanykind.Morsecodecanalsobetransmittedinavarietyofformsincludingaudiotones,radiosignals,electricalsignals,andvisualsignalssuchasablinkingLED.RadiosignalingofMorsecodeisusuallyinanon-offkeyedmanner,requiringlesscomplexequipmentthanotherradiocommunicationtechnologies.

YoumaybewonderingwhyonewouldwanttodevelopaMorsecodegeneratorforOzobotBit.Themaineducationalpurpose,asseenbytheauthorofthispaper,isthatdoingsopresentsagreatopportunityforthestudenttolearnhierarchicalmodularprogrammingbytheuseoffunctions.Theadvantagesofsuchmodularityincludeeasierprogramming,reductionincodingtime,avoidingrepetitionofcode,easiermaintenanceduetotheabilitytolocateandquicklychangevaluesofparameters,andprogramsthatrequirelessmemory.ReductioninrequiredmemoryforprogramsisparticularlyimportantwhenprogrammingsmalldeviceswithlimitedmemorylikeOzobotBit.

2

MorseCodeStructure

Morsecodesexistforletters,numbers,andspecialcharacters,andincludeabbreviationsforcommonlyusedwords.Figure1showstheInternationalMorsecodesforlettersandnumbers.

Figure1

Thecodingprocessmakesuseofashorttimegapbetweenelementalpartsofthesameletter,alongergapbetweenletters,andanevenlongergapbetweenwords.Supposethatthelengthofadotisonetimeunit.ThentheInternationalTelecommunicationUnion(ITU)definesthefollowingregardingthespacingandlengthofsignals:

• Thelengthofadotisonetimeunit.• Thelengthofadashisthreetimeunits.• Thespacebetweenelementalpartsofthesameletterisonetimeunit.• Thespacebetweenlettersisthreeunits.• Thespacebetweenwordsisseventimeunits.

Withtheaveragelengthofawordbeingsixletters,thefollowingformulagivesagoodapproximationforthetimelength,T,inmilliseconds,ofthetimeunit,assumingthatthegoalisthetransmittalofWwordsperminute(WPM).

𝑇 = 1200𝑊

Forexample,20WPMwouldmeanthatthetimeunitwouldbe60ms.

3

FunctionsfortheOzobotMorseCodeProgram

Figure2showsasuggestedsetofhierarchicaluserdefinedfunctionsforprogrammingOzobotBittoblinktheMorsecode.Thelowestlevelfunctionsareintheleftmostcolumn,withprogressivelyhigherlevelsasonemovestotheright.Anexampleofatypicalmainprogramisshownintherightmostcolumn,whereOZOBOTMYTINYROBOTissettoblink10timesinMorsecode.KeepinmindthatthesuggestedfunctionsarebasedonusingOzoBlocklyblocksavailablein“Advanced”mode4.Capabilitiesof“Master”mode5,withplanstosupportlow-levelcontrolfunctionsandadvancedprogrammingfeatures,areunknowntotheauthoratthewritingofthisdocument.ThesecapabilitiescouldpossiblyresultinadifferentapproachtoprogrammingOzobottoproduceMorsecode.

Figure2

ReferringtoFigure2,thelowestlevelfunction“options”iswherethevaluesofallvariablescontainingnumericconstantsaredeclared.Thisprovidesasinglelocationwhereadjustmentsofthesevaluescanbemade.Forexample,abeginnerwhoislearningMorsecodemaywanttoincreasethetimebetweendotsanddashes,thetimebetweenletters,andthetimebetweenwords.ThisalsoprovidesasinglelocationwherethecolorthatOzobotblinksitsMorsecodecanbeadjustedbysettingthered,green,andbluecomponentsoftheLED’scolor.Suggestedvariableswithconstantvaluesthatcanbedeclared:

4

• Threevariablestoholdthevaluesforthered,green,andbluecomponentsoftheLED’scolor• Twovariablestoholdthenumberoftimeunitsfordotsanddashes• Threevariablestoholdthetimeunitspacingbetweendotsanddashes,betweenletters,and

betweenwords• Avariabletosetthedesiredwordsperminute(WPM)forthegeneratedMorsecode• Avariabletocomputethetimelengthforthebasictimeunit.Keepinmindthatyouwillbe

usingtheOzoBlocklyblock“wait…x10ms”,soyouwillwanttosetthetimeunitto120/WPMratherthan1200/WPMsincetheblockmultipliesx10ms.

YoumayalsofindithelpfulintheoptionsfunctiontoinitiallysettheLEDtowhiteforthreeseconds,andthenturnitOFFforasecondbeforeflashingtheMorsecode.

Movingontothenextcolumnoffunctions,firstconsiderthe“turnLEDon”userdefinedfunction.WhilethereisanOzoBlocklyfunctionto“turnLEDoff”,thereisnoOzoBlocklyblockthatturnstheLEDonwithacolorthatcanvary.However,youcanturntheLEDonbyusingtheOzoBlocklyblock“setLEDcolor”andusethevariablesforred,green,andbluethatyoudefinedintheoptionsfunction.

Theuser-definedfunctions“dotdashspace”,letterspace,andwordspacesimplyturntheLEDoffandthenwaittheappropriatenumberofmilliseconds.

Movingontothenextcolumnofuser-definedfunctions,theuser-definedfunctions“todot”and“todash”,eachcall“turnLEDon”,waittheappropriatenumberofmilliseconds,andtheturnofftheLED.

Movingontothehighestleveluserdefinedfunctions,weseethatthereare26ofthem,oneforeachletterofthealphabet.(YouprobablywillnothaveenoughmemoryinyourOzobotBittoincludethenumbers0through9inyourcodes.)Eachofthese26letterfunctionswillmakeuseofthetwomiddlelevelsofuserdefinedfunctions,accordingtothedefinitionsoftheInternationalMorsecode.

Thatprettymuchsetsthestageforyourprogrammingchallenge.Enjoy!

Ifyou’dliketoseeashortvideooftheOzobotBitMorsecodegeneratorinaction,visitthislinkonYouTube:

https://youtu.be/cUc4m261nXg

Inthisvideo,Ozobot’sblinkingLEDhasbeeninterfacedwithasimplelittleBitscircuitthatconvertstheLEDsignalsfromOzobottosoundsonaspeaker.ThecodedmessageisOzobotMyTinyRobot.Notethatonecouldreplacethespeakerwithavibrationmotor.Thisvibrationmotorcouldbeattachedtoadeafandblindperson’sskin.IfthispersonknowsMorsecode,heorshecouldinterpretthecodethroughthesenseoftouchontheskin.

Recommended