Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
BySanjayandArvindSeshan
INTERMEDIATEPROGRAMMINGLESSON
DATAWIRES
LessonObjectivesLearnwhatDataWiresareandhowtousethem
Prerequisites:DisplayBlock,SensorBlock,BrickButtons
COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 2
DataWiresADataWireallowsyoutotakeanoutputfromoneprogrammingblockandinputitintoanother.
COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 3
InputOutput
DataWireTypes
COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016
4
DataType Input Output Output DataWireLogic TrueorFalse
Numeric Number
Text Text
NumericArray
LogicArray
ImagesfromEV3Help
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).
HowtoCreateaDataWireTheblockwiththeoutputmustbeplacedbeforetheblockwiththeinput
Theinputandtheoutputmustbethesamedatatypeoronethatcanbeautomaticallyconverted(seeslides4and5)
1.Clickontheoutputontheblock
2.Holdanddragthewire.
3.Movetheiconintothecorrectinputandthenletgoofthemouse
COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 6
1
2
3
ImagesfromEV3Help
Sidebar:DisplayBlock- WiredModeTheDisplayBlockcanbeusedinwiredmodetodisplaydatafromanotherblocktothescreen.
Forthechallenge,youwillneedtodisplayanumberonthescreen.PickTextModeàGridfromthebottomleftcorneroftheblock.
TopickWiredMode,clickonthetoprightcorneroftheDisplayBlockandpickwired
COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 7
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
ChallengeSolution
COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 9
MoreComplexWiring:Switches
COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 10
A. Ifyouwanttodragdatawiresoutofswitches,youwillneedtochangetheswitchtotabbedview
A
C C
B
B.Onceyouswitchtotabbedview,youcandragdatawiresout
C.Differentoptions intheswitchcanconnecttothesamewire
MoreComplexWiring:LoopsYoucanconnectwiresbothintoandoutofalooplikeintheexamplebelow
COPYTIGHT©2015EV3LESSONS.COM,LASTEDIT7/06/2016 11
• Notethatthedatacomingoutoftheloop through thewirewillonlybethelastpassthrough theloop.
• Intheexampleabove,thecolorsensor isreadtwiceintheloop.However,thedatawirewillonlyhavethesecond (andlast)readingandthatsecondreadingwillbedisplayed.
Goingintotheloop
Goingouttheloop
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.