intermediate programming lesson · how to create a data wire the block with the output must be...

12
By Sanjay and Arvind Seshan INTERMEDIATE PROGRAMMING LESSON DATA WIRES

Upload: others

Post on 01-Nov-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

BySanjayandArvindSeshan

INTERMEDIATEPROGRAMMINGLESSON

DATAWIRES

Page 2: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

LessonObjectivesLearnwhatDataWiresareandhowtousethem

Prerequisites:DisplayBlock,SensorBlock,BrickButtons

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 2

Page 3: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

DataWiresADataWireallowsyoutotakeanoutputfromoneprogrammingblockandinputitintoanother.

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 3

InputOutput

Page 4: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

DataWireTypes

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016

4

DataType Input Output Output DataWireLogic TrueorFalse

Numeric Number

Text Text

NumericArray

LogicArray

ImagesfromEV3Help

Page 5: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

AutomaticDataWireConversions

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 5

FromDataType ToDataType Output/Result

Logic Numeric False=0,True=1

Logic Text False= “0”,True=“1”

Logic LogicArray Arraywithoneelement

Logic NumericArray Arraywithoneelement(0or1)

Numeric Text Text thatrepresentsanumber

Numeric NumericArray Arraywithoneelement

LogicArray Numeric Array Same sizearraywithallelementsequalto0or1

ContentfromEV3Help

Theseconversionsareautomaticallyperformed intheprogramming blocks.Forexample,youareallowedtoconnectanumericvalue(likewhatcolorasensorsees)toatextvalue(onadisplayblock).

Page 6: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

HowtoCreateaDataWireTheblockwiththeoutputmustbeplacedbeforetheblockwiththeinput

Theinputandtheoutputmustbethesamedatatypeoronethatcanbeautomaticallyconverted(seeslides4and5)

1.Clickontheoutputontheblock

2.Holdanddragthewire.

3.Movetheiconintothecorrectinputandthenletgoofthemouse

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 6

1

2

3

ImagesfromEV3Help

Page 7: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

Sidebar:DisplayBlock- WiredModeTheDisplayBlockcanbeusedinwiredmodetodisplaydatafromanotherblocktothescreen.

Forthechallenge,youwillneedtodisplayanumberonthescreen.PickTextModeàGridfromthebottomleftcorneroftheblock.

TopickWiredMode,clickonthetoprightcorneroftheDisplayBlockandpickwired

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 7

Page 8: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

DataWiresChallengeCHALLENGE:Makeyourrobotdriveforwardslowlyoverdifferentcolors.Havetherobotdisplaythecolorthecolorsensorseesasitmoves.Stopwhenyouhitabuttononthebrick.

STEP1:TurnthemotorsoninaSteeringBlockanddriveslowlyforward

STEP2:◦ InsideaLoop,addaColorSensorblock.◦ AddaDisplayBlockinWired,TextGridModes.◦ WiretheSensorBlock’soutput intotheDisplayBlock’s

textinput (firstinput)

STEP3:Exittheloopwhenabrickbuttonispressed

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 8

Page 9: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

ChallengeSolution

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 9

Page 10: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

MoreComplexWiring:Switches

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 10

A. Ifyouwanttodragdatawiresoutofswitches,youwillneedtochangetheswitchtotabbedview

A

C C

B

B.Onceyouswitchtotabbedview,youcandragdatawiresout

C.Differentoptions intheswitchcanconnecttothesamewire

Page 11: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

MoreComplexWiring:LoopsYoucanconnectwiresbothintoandoutofalooplikeintheexamplebelow

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 11

• Notethatthedatacomingoutoftheloop through thewirewillonlybethelastpassthrough theloop.

• Intheexampleabove,thecolorsensor isreadtwiceintheloop.However,thedatawirewillonlyhavethesecond (andlast)readingandthatsecondreadingwillbedisplayed.

Goingintotheloop

Goingouttheloop

Page 12: INTERMEDIATE PROGRAMMING LESSON · How to Create a Data Wire The block with the output must be placed before the block with the input The input and the output must be the same data

Credits◦ ThistutorialwaswrittenbySanjayandArvindSeshan◦ Morelessonsatwww.ev3lessons.com

COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 5

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.