introduction to my blocks - ev3 lessons · introduction to my blocks. lesson objectives learn how...

18
By Sanjay and Arvind Seshan INTERMEDIATE PROGRAMMING LESSON INTRODUCTION TO MY BLOCKS

Upload: others

Post on 19-Aug-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

BySanjayandArvindSeshan

INTERMEDIATEPROGRAMMINGLESSON

INTRODUCTIONTOMYBLOCKS

Page 2: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

LessonObjectivesLearnhowtomakecustomblocksintheEV3Software(MyBlocks)

LearnwhyaMyBlockisuseful

LearntoconstructaMyBlockwithInputsandOutputs(Parameters)

Note:ThenewfeaturesmentionedinthislessonareavailableinV.1.3ofbothHomeEditionandEducationEdition.Updateyoursoftwareifyouarenotrunningthisversion.

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 2

Page 3: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

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

Page 4: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

WhendoYouUseaMyBlock?• Whenevertherobotisgoingtorepeatanactioninside

yourprogram

• Whencodeisrepeatedinadifferentprogram

• Organizeandsimplifyyourcode

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 4

Page 5: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

WhyShouldYouBother?BecauseofMyBlocks,yourmissionswilllooklikethis…

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 5

Insteadofthis….

Thismakesyourcodeeasiertoreadandeasiertomodify!!!

Page 6: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

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

Page 7: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

Step1:HighlightBlocks

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 7

• Forthislesson,ourgoalistomoveadesiredamountofrotations atadesiredpowerandreturntheultrasonicvalue attheend

• Step1:SelectthetwoblocksinthecodethatyouwanttoturnintoaMyBlock

• Question:Whatwouldbetheinput(s)andoutput(s)forourMyBlock?

• Answer:Theinputsarepowerandrotations.TheOutputisdistancemeasuredbytheultrasonicsensor.

Page 8: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

Step2:LaunchMyBlockBuilder

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 8

• A:GotoToolsàMyBlockBuilder- Ifyouencounteranerror,viewthenextslide

• B:PickaMyBlockName

• C.AddaDescription

• D.SelectanIconforthewholeMyBlock

MoveRotationsandoutputUltrasonic

A

B C

D

Page 9: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

CommonErrorMessagesERROR1:

SOLUTION:YouneedtohighlighttheblocksbeforegoingintoMyBlockBuilder

ERROR2:

SOLUTION:Un-highlightthestartblockbeforegoingintoMyBlockBuilder

Ifyoucontinuetohavetroubleatthisstep,justselectasingleblockinyourprogramandcreateaMyBlockfromit.YoucaneditandaddmoreblockstoaMyBlockatanytime.Youcanevenchangetheinputsandoutputs* ofaMyBlockaftercreation.

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 9

*Newfor2017

Page 10: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

Step3:AddInputs/Outputs

A.Weneedtoaddtwoinputsandoneoutputsowewillclickthe+buttonthreetimes

B.Gobacktothefirstparameter

C.GotoParameterSetup

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 10

MoveRotationsandoutputUltrasonic

MoveRotationsandoutputUltrasonic

A

B

C

Page 11: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

Step4:SetupParameterforPower

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 11

B.SelectInputA.PickaName

D.Chooseadefaultvalue

MoveRotationsandoutputUltrasonic

Setmin&maxvalues(onlyavailablewithslider)

C.PowerisaNumber

E.ChoosebuttonStyle

ABCD

E

Page 12: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

Step5:SetupParameterforRotation

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 12

MoveRotationsandoutputUltrasonic

Nowclickonthesecondparameter

ABCD

E

B.SelectInputA.PickaName

D.ChooseadefaultvalueC.RotationisaNumber

E.ChoosebuttonStyle

Page 13: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

Step6:SetupParameterforUltrasonic

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 13

MoveRotationsandoutputUltrasonic

ABC

Nowclickonthethirdparameter

B.SelectOutput

A.PickaName

C.UltrasonicoutputisaNumber

Page 14: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

Step7:SetupParameterIcons

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 14

Inthisstep,wewillchangetheiconsfortheparametersfrom“a”toanimageofyourchoice.

A. Clickonaparameter

B.ClickonthetabParameterIconsifnotalreadyonthistab,andchooseanicon

C.RepeatstepsAandBforeachparameter

D.PressFinishwhenyouaredone.

A

B

C

Page 15: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

Step8:AddDataWiresA. WhenyouclickFinish(onprevious

slide)youwillseethis.

B. WireuptheMyBlockbydraggingadatawirefromeachparametertoitscorrespondingslotonthemovesteeringblockandsensorblock.

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 15

Thesegreyblocksareourinputs/outputs(parameters)thatweresetupautomaticallybytheMyBlockBuilder

Page 16: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

WhereistheMyBlock?A. YourMyBlockwillappearinthe

turquoisetab.Youcannowusethisblockinanyprogram.

B. Below,thesameMyBlockisusedtwice.Oncetomoveforward2rotationsandthenbackwards5rotations.

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 16

Note:ThesameMyBlockcanbeusedwithdifferentinput

values.

Page 17: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

EditingYourNewlyCreatedMyBlock

©2015EV3LESSONS.COM(LASTEDIT9/25/2017) 17

IfyouwanttochangeanythingintheMyBlockyoujustcreated,simplypressonthe“Edit”buttononthetopLeftcorneroftheMyBlock*

Youcanchangethename,addordeleteparameters,etc.

*Newfor2017

Page 18: INTRODUCTION TO MY BLOCKS - EV3 Lessons · INTRODUCTION TO MY BLOCKS. Lesson Objectives Learn how to make custom blocks in the EV3 Software (My Blocks) Learn why a My Block is useful

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.