ADVANCED EV3 PROGRAMMING LESSONev3lessons.com/en/ProgrammingLessons/advanced/Bluetooth.pdf · ì...

Post on 28-Mar-2020

8 views 0 download

Transcript of ADVANCED EV3 PROGRAMMING LESSONev3lessons.com/en/ProgrammingLessons/advanced/Bluetooth.pdf · ì...

ADVANCEDEV3PROGRAMMINGLESSON

IntroductiontoBluetoothBySanjayandArvindSeshan

ì LearnhowtousetheBluetoothfunctionalityonyourEV3

ì Learntosendandreceivemessages betweenEV3bricks

Objectives

CopyrightEV3Lessons,2016,LastEdit7/19/2016

ì Bluetoothusesradiofrequenciestocommunicatebetweendevices

ì TheEV3usesBluetoothtodownloadprogramswirelessly

ì TheEV3alsousesBluetoothtoconnecttoanotherEV3

WhatisBluetooth?

CopyrightEV3Lessons,2016,LastEdit7/19/2016

ì Coordinatingmultiplerobotsì Havethemperformsimilar

actionsì Synchronizetheiractions

CopyrightEV3Lessons,2016,LastEdit7/19/2016

WhyUseBluetoothontheEV3?

ì Controllingalargesinglerobotwithmultiplebricks

ì Analternativetodaisychaining:Requireslesswiringbutneedsseparateprograms

ì Giveeachbrickanuniquename(SenderandReceiverforthislesson)

ì UseanUSBcablefordownloadingcodetothebricks(ratherthanBluetooth).YoucannotconnectbetweenEV3sandaPCatthesametime

ì Turnonthereceiverrobotfirstthenthesenderinthechallengesinthislesson.ThisisbecausethechallengesolutiononlysendsthemessageonceinChallenge1.

TipsforSuccess

CopyrightEV3Lessons,2016,LastEdit7/19/2016

ActivatingBluetoothontheEV3

ì TurningonBluetooth:ì OntheEV3menu,gotothe

symbolthatlookslikeawrenchì Godowntotheword“Bluetooth”

andactivateit

ì ToconnecttoanotherbrickgobackintotheBluetoothmenuì Goto“Connections”ì Select“Search”andfindtheother

brick’sname

ì YoucanalsomanageyourconnectionswiththeBluetoothConnectionBlock.Butwedonotusethisblockinthislesson.

CopyrightEV3Lessons,2016,LastEdit7/19/2016

ì ThemessagingblockcanbefoundintheBluePallet.

ì YouwillalsousetheWaitForblockinMessagingMode

NewBlock:Messaging

CopyrightEV3Lessons,2016,LastEdit7/19/2016

ì Senda“HelloWorld”messagefromonebricktoanother

ì Thesecondbrickshouldreceiveanddisplaythemessageonitsscreenfor5seconds

ì Tips:ì Youwillneedtopairthetwo

robotsaheadoftimeì NameonerobotSenderandthe

otherReceiverforthischallengeì Forthischallenge,youwilluse

theMessagingblockà SendàText

ì YouwillusetheWaitForblockintheMessagingModeà Changeà Text

Challenge1

Video

CopyrightEV3Lessons,2016,LastEdit7/19/2016

Challenge1Solution

CodeontheSenderRobot

CodeontheReceiverRobot

Sendsthemessage“HelloWorld”totheReceiverrobot.Themessagetitle“Greeting”mustmatchinthereceiver’sprogram.

Waitforamessagefromthefirstrobotanddisplaythetextfor5seconds

CopyrightEV3Lessons,2016,LastEdit7/19/2016

ì Movethefirstrobotbyhandandsendthemotors’powertotheotherrobot

ì Havethesecondbrickreceivethedataandcopythemovement

Challenge2:SynchronizedSwimmers

CopyrightEV3Lessons,2016,LastEdit7/19/2016

Challenge2Solution

CodeontheSenderRobot

CodeontheReceiverRobot

CopyrightEV3Lessons,2016,LastEdit7/19/2016

Readeachofthemotors’powerandsendthemusing twodifferentmessagetitlestotheReceiverrobot

Readthetwodifferentmessagetitlesandapplythereceivedpowervalues

ì OnceyouknowhowtouseBluetoothontheEV3,youcancreatecomplexrobotswheremovement iscoordinatedandsynchronized

ì MasterLeeMagpili’s EagleisanexampleofsuchaprojectwhereBluetoothmessagesareusedtocoordinatehead,legandwingmovement.(Photosandcodepostedwithpermission.) AnotherbrickusesBluetooth toremotelycontroltheEagle.

ì Thisprojectrequires thefollowing partsforthebirdandaremote:ì 5EV3sì 17Motorsì 2TouchSensors

PuttingitallTogether

CopyrightEV3Lessons,2016,LastEdit7/19/2016

CopyrightEV3Lessons,2016,LastEdit7/19/2016

TheEagle

ThisissmallpartoftheEagle’scode.HereyouseethattheEaglehasfivemodes.Inthisview,youseethatmessagesarebeingsentto“Legs1”and“Wings”EV3bricks.

ThankyoutoMasterLeeMagpili forsharinghiscodewithEV3Lessons.