introduction to my blocks - ev3 lessons · introduction to my blocks. lesson objectives learn how...
TRANSCRIPT
BySanjayandArvindSeshan
INTERMEDIATEPROGRAMMINGLESSON
INTRODUCTIONTOMYBLOCKS
LessonObjectivesLearnhowtomakecustomblocksintheEV3Software(MyBlocks)
LearnwhyaMyBlockisuseful
LearntoconstructaMyBlockwithInputsandOutputs(Parameters)
Note:ThenewfeaturesmentionedinthislessonareavailableinV.1.3ofbothHomeEditionandEducationEdition.Updateyoursoftwareifyouarenotrunningthisversion.
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 2
WhatisaMyBlock?• AMyBlockisacombinationof
oneormoreblocksthatyoucreatethatcanbegroupedintoasingleblock
• MyBlocksarebasicallyyourowncustomblocks
• OnceaMyBlockiscreated,youcanuseitinmultipleprograms
• JustlikeanyotherblockinEV3,MyBlockscanhavebothinputsandoutputs(parameters)
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 3
ThetwoblocksaboveareexamplesofMyBlocks:• Move_Inches tellstherobotto
movethenumberofinchesweinput
• Turn_Degrees tellstherobottoturntheamountweinput
• TheseMyBlockswillbetaughtinseparatelessons.
CM
WhendoYouUseaMyBlock?• Whenevertherobotisgoingtorepeatanactioninside
yourprogram
• Whencodeisrepeatedinadifferentprogram
• Organizeandsimplifyyourcode
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 4
WhyShouldYouBother?BecauseofMyBlocks,yourmissionswilllooklikethis…
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 5
Insteadofthis….
Thismakesyourcodeeasiertoreadandeasiertomodify!!!
WhatMakesaUsefulMyBlockNote:MakingMyBlockswithinputsandoutputscanmakethemfarmoreuseful.However,youneedtobecarefulnottomaketheMyBlocktoocomplicated.
Question:LookatthelistofthreeMyBlocksbelow.Whichonesdoyouthinkareusefulfortouse?◦ Move5CM(Movestherobotfivecentimeters)◦ MoveCM withacentimeterandpowerinput◦ MoveCM withcentimeter,power,angle,coast/brake,etc.inputs
Answer:◦ Move5CMmaybeusedoften,butyouwillbeforcedtomakeotherMyBlocksforotherdistances.Thiswillnotbefixablelater.
◦ MoveCM withcentimetersandpowerasinputsisprobablythebestchoice.◦ MoveCM withcentimeters,power,angle,coast/brake,etc.mightbemostcustomizable,butsomeoftheinputsmightneverbeused.
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 6
Step1:HighlightBlocks
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 7
• Forthislesson,ourgoalistomoveadesiredamountofrotations atadesiredpowerandreturntheultrasonicvalue attheend
• Step1:SelectthetwoblocksinthecodethatyouwanttoturnintoaMyBlock
• Question:Whatwouldbetheinput(s)andoutput(s)forourMyBlock?
• Answer:Theinputsarepowerandrotations.TheOutputisdistancemeasuredbytheultrasonicsensor.
Step2:LaunchMyBlockBuilder
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 8
• A:GotoToolsàMyBlockBuilder- Ifyouencounteranerror,viewthenextslide
• B:PickaMyBlockName
• C.AddaDescription
• D.SelectanIconforthewholeMyBlock
MoveRotationsandoutputUltrasonic
A
B C
D
CommonErrorMessagesERROR1:
SOLUTION:YouneedtohighlighttheblocksbeforegoingintoMyBlockBuilder
ERROR2:
SOLUTION:Un-highlightthestartblockbeforegoingintoMyBlockBuilder
Ifyoucontinuetohavetroubleatthisstep,justselectasingleblockinyourprogramandcreateaMyBlockfromit.YoucaneditandaddmoreblockstoaMyBlockatanytime.Youcanevenchangetheinputsandoutputs* ofaMyBlockaftercreation.
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 9
*Newfor2017
Step3:AddInputs/Outputs
A.Weneedtoaddtwoinputsandoneoutputsowewillclickthe+buttonthreetimes
B.Gobacktothefirstparameter
C.GotoParameterSetup
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 10
MoveRotationsandoutputUltrasonic
MoveRotationsandoutputUltrasonic
A
B
C
Step4:SetupParameterforPower
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 11
B.SelectInputA.PickaName
D.Chooseadefaultvalue
MoveRotationsandoutputUltrasonic
Setmin&maxvalues(onlyavailablewithslider)
C.PowerisaNumber
E.ChoosebuttonStyle
ABCD
E
Step5:SetupParameterforRotation
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 12
MoveRotationsandoutputUltrasonic
Nowclickonthesecondparameter
ABCD
E
B.SelectInputA.PickaName
D.ChooseadefaultvalueC.RotationisaNumber
E.ChoosebuttonStyle
Step6:SetupParameterforUltrasonic
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 13
MoveRotationsandoutputUltrasonic
ABC
Nowclickonthethirdparameter
B.SelectOutput
A.PickaName
C.UltrasonicoutputisaNumber
Step7:SetupParameterIcons
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 14
Inthisstep,wewillchangetheiconsfortheparametersfrom“a”toanimageofyourchoice.
A. Clickonaparameter
B.ClickonthetabParameterIconsifnotalreadyonthistab,andchooseanicon
C.RepeatstepsAandBforeachparameter
D.PressFinishwhenyouaredone.
A
B
C
Step8:AddDataWiresA. WhenyouclickFinish(onprevious
slide)youwillseethis.
B. WireuptheMyBlockbydraggingadatawirefromeachparametertoitscorrespondingslotonthemovesteeringblockandsensorblock.
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 15
Thesegreyblocksareourinputs/outputs(parameters)thatweresetupautomaticallybytheMyBlockBuilder
WhereistheMyBlock?A. YourMyBlockwillappearinthe
turquoisetab.Youcannowusethisblockinanyprogram.
B. Below,thesameMyBlockisusedtwice.Oncetomoveforward2rotationsandthenbackwards5rotations.
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 16
Note:ThesameMyBlockcanbeusedwithdifferentinput
values.
EditingYourNewlyCreatedMyBlock
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 17
IfyouwanttochangeanythingintheMyBlockyoujustcreated,simplypressonthe“Edit”buttononthetopLeftcorneroftheMyBlock*
Youcanchangethename,addordeleteparameters,etc.
*Newfor2017
CreditsThistutorialwascreatedbySanjaySeshanandArvindSeshan
Morelessonsareavailableatwww.ev3lessons.com
©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 18
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.