Oh, well, physically I haveithereinmyhandOrdoweknowisthismicroprocessormicrocontrollerwhereessentiallyyoucanput a bunchofelectroniccomponentstogetherandcontrolthemtogether?
We'llteachyouthebasicelectricalengineering, butifyouwanttoknowmoreadvancedthan I wouldhighlyrecommendcheckingoutbooksareaskingortakingoutonlineformore.
Resourceisnextisworkingtypeofdifferenttypesofaredoing a boardsmostaredoingawardsareaboutthesame.
Youknow, wehave a lotofwires, andasyoucanseewiththesebreadboards, there's a lotofwiringinvolved.
Wehaveseveralbreadboards, butyoujustneedone.
Andthenwehavethiscabletotransferthecodefromourlaptoptothe R.
Doweknow?
Thenwehaven't led a button.
Severaltypesofresistors, a potentialometerultrasonicsensorand a servalfirstgettingsettled.
Soaredoingoh, can't berunontheCS 50 e becausetheCS 50 i d doesn't haveit.
However, I wouldhighlyrecommenddownloadingandinstallingtheArduinointoyourcomputerbecausethisisthebestwayyoucanworkwiththehardware, andalsoyoucanworkoffline.
However, ifyouareinclinedtoworkontheInternetaredoingOh, doeshave a Webbasededitor, whichis a cloudversion.
Youcanfollowthelinktherepostedontothescreen, andyoucanseethecloudsoftwaretheyhaveavailabletoworkwitharedoing a code.
Electricityflowsfrompositivetonegativetogroundsowecanseeherewiththissimplecircuitthatelectricityflowsfromthepositiveflowsfromthepositivewiredownthenegativewireandfromthenegativewiredgoestothegroundsoyoucanimagineitas a waterfallanalogywherewehaveourwatersource a topwateror a K A.
Electricityisflowingthrough a circuituntilhereachesthelowestpointpoint, a k eightgroundandallcomponentsinthiscircuithavetoobeythislaw.
Forinstance, if I stick a metalwireintotheoutlet, obviouslythere's gonnabeelectricflowflowingthereandfromthesewires, What I meanbysamewire, samerail, sameflowisthatthesamequoteunquoteelectricsignalisgoingtobeflowingbetweenthesewires.
Sothisentirecolumnmeansthatif I stick, let's say a signalfrompinninethere, thiswholerailwillcontainthesignalfrompinnine, becauseelectricity, aswe'veseenfromhere, flowsfrompositivetonegativetheground.
Sofirstlineofcodeisthisis a typicalcommonpracticesfirsttoclearyourlibraries, butinthiscase, we'rejustsimplywanttoturnonledonandoff, makeitblink a littlebit, sowedon't needanylibraries, butthefirstthingwewanttodoisgivethepin a name.
Thewaythatthelake a manworksisthatitusesmicrosecond.
Sojustdosomeofthemathwe'llget.
Thismeansthatdelay 1000 meansDeLayforonesecond.
Nextiswe'regonnaturnofftheled.
So, asbeforehere.
Quitetheopposite.
Firstwewritewroteittoohigh.
Nowwe'resettingthatsamepin, butwe'resettingittoolow a k We'recuttingoffallvoltageflowingtoit, orwe'remakingzerovoltsflowtoothyled, andthenwe'regonnadelayagainjusttomakesurethat, youknow, wegot a nicepatternofblinkof a blinkingled.
Okay, sowhatwe'regonnadoiswe'regonnauploadthis.
Youcanpressthisbutton, right?
Appearinthecorner, theonewiththearrowpointingtotherightclickuploadusefulthingabouttheordoweknowisthat I d.
Now, I wouldarguethatthissegmentisgoingtobe a littlebitmoredifficultbecauseofthelogicinvolvedwithbuttons, butessentially, a buttonisjustyouprep, youjustpress.
Thisisessentiallylikethisswitchthatyoupressedtosendoutcommands, sothinkof a buttonaslike a lightswitch.
Butwejustwanttomakesuretoforclarification, setclarificationssakethatwesetthisasnowin a voidLukefunction.
Let's readtowhat's happening.
Soifthejewelrybuttonequalslow, Sowhatthismeansisthatif I pressthebuttonrighthereandsoifwepressthebutton, itgivesthesignalhighbecauseremember, as I said, a buttoniskindoflike a switch.
Thinkof a buttonas a switchthattellthatconnectsthiselectricalwirestocontinuetheflowofelectricity.
Now I won't getintoomuchdetailaboutthis, butthesethingsarecalledpullupresistors, andthereasonwhyweincludethisresistorinbetweenistopreventsomeweirdreadingsfromhappening, becauseifweweretoremovethatresistor, theledwouldturnonandoffbecauseofmixedelectricalsignalscomingfromaroundus.
Isthatwhenyoupushedthebuttonagainsobacktowhat I wassayingaboutthis.
Thebouncingthing.
Nowyoucan, asyoucanseehere, thisissomemixedelectricalsignalthat's comingfrom a button.
If I weretopressthebuttonfor a fewmicroseconds, theelectricsignalisgoingtobefluctuating.
Sowewanttomakesurewepreventthatfromhappening.
Orwewanttomakesurethatokay, weonlyreadthestateofwhathappensafterwepressthatbuttonafterthosefivemillisecondsbecauseinbetweenthetimethingsget a littlebitfinicky.
So, forinstance, inthebeginning, offthecircuit, whenwehaven't pushedthebuttonwhentheledisoff, previousstateandcurrentstateisgoingtobebothlow.
Butoncewerunintothislinethatthebouncewhen I pressedthebuttoncurrentstatenowisgoingtobetrueorhigh, butpreviousstatewillstillbelow, soitpreviouslyitmeanslowandcurrentstatemeanshigh.
Sofeelfreetousethisas a boilerplatetemplatebecausethisis a commonthingyou, youyouwanttobeusingforyouraredoingOh, andsamethingforthehardwarewhereyouhavethebuttonhere, somevoltagetotherightstotheleftsideandsomeoutputtotheleftsidewith a resisterinbetween.
Thisisessentially a waytoseewhat's happeningandis a usefuldebuggingtechniquealso, andwealsowerewewanttoputouttheoutputbecauseprintthebuggingisusefulinsoftware, butit's alsoveryusefulandhardwaretoseenotonlywhat's happeningwellWhatkindofinputsarewegettingnow?
As I'vesaidbefore, they'vethey'reusing a lotofthings.
Forinstance, in a speaker, whenyouturntheknobwhenheturneduptothemaximum, you'returningtheresistanceverylowbecausesoundisessentiallyjust a bunchofelectricsignals.
Now I'm goingtobeturningthisknobandseewhathappenstothevalues, andyoucanseeit's slowlystartingtodecrease.
Now, thesecorrespondtothevariousresistancevaluesbecausethisis a 10 K resistor.
Butwiththatmapfunctionthathementionedearlier, thiscouldbeusedformany, manythingssuchas, Oh, howbrightdo I wantmyledtobe, orwhatcolorshould I saidittoo?
Butforinstance, ifyou'redoing a physicslabandyouwanttomeasurehowfasttheobjectistraveling, youwantthewaythisthingwillworkisitsendsout a soundsignalfromoneend, andanditmeasureshowlongittakesforthatsignaltocomebackintheother.
Let's say I havethisbookoverhere, and I'llpointit a bitrighthereandnoticethatas I movecloserthatthisdistanceisgettingsmallerandthatastheymovefurther, thedistanceisgettinglarger.