model railway animation: part 1, leds - expanded by david kingmodel railway animation: part 1, leds...
TRANSCRIPT
ModelRailwayAnimation:Part1,LEDs-ExpandedByDavidKingBynowyouaremostlikelyreadytoproceedpastthesimpleBlinksketchsothatiswhatwewilldonow.Acoupleofsimplesketcheswecancreatewillbetosimulateasimplegradecrossingflasherandatrafficlight.AquicknoteabouttheLEDitselfisthatyoumayhavenoticedthatitmaynothaveworkedforyouatfirstandthereisapossiblereasonwhythismightofhappened.TheLEDsinkitshave2leadswithonebeinglongerandtheothershorter.TheLongleadistheanodeanditneedstobeconnectedclosesttothe+5voltpowerandtheshortedleadisthecathodeandshouldbelocatedclosesttothegroundconnection.Wealsousearesistorconnectedfromtheanodeto+5voltsorfromthecathodetoground.Itdoesn’tmatterwhichlocationtheresistorisplacedinthecircuitjustaslongasitisinthecircuit.IfatfirsttheLEDdoesn’tlightchecktoseeifyouhavetheLEDwiredupbackwards.IfitisbackwardsremovetheLEDandturnitaroundtoswapthoseleads.WhenusingaLEDwiththeoutputofArduinoUnoitisokayto1or2LED’stoasinglepin.Theoutputfromeachpinhasamaximumratingofabout40milliampsandeachLEDconnectedcandrawupto20milliamps.Asyoucanseeifyouconnect2LEDstoasingleoutputyoucouldbeatthelimitforthatpin.Withallofthatsaidthereisawaytoconnect2LEDstoasinglepinthatonlyusesthe20milliampsandnotthe40milliamps.ThiscanbeaccomplishedbythewayweconnecttheLEDsinthecircuitbyconnectingtheLEDsinparallelorseries.Thisimageshouldhelpmakethisalittleclearer.
TheGradeCrossingFlasherThegradecrossingflasherisjustapairofLEDsorsetsofpairsofLEDsthatneedtoflashatasetrateofspeedandeachLEDpairmusthaveoneLEDonwhiletheotherisoff.ThisisthealternatingpatternofLEDsthatwewant.Intherealworldthisalternatingflashinghappensataboutarateof1/3rdasecondforeachoftheLEDs.Thisisthetimethatwewillusetokeepiteasy.Yourcompletedsketchwouldbesimilartomysketchshownbelow.
InthissketchitisjustamatterofadjustingthetimesfromtheoriginalBlinksketchandaddingtheadditionoutputsforbothpinModeanddigitalWrite.AsseeninthissketchIhaveconnected4LEDstotheArduinoUnojusttokeepthewiringverysimple.ThereareothermethodsofwiringtheLEDsbutthisissimpletounderstandandeasytoconnect.IhavecreatedaFitzingdiagramtoshowyouhowtoconnectthewirestotheLEDsalongwithusingsomeresistors.RememberthattheresistorvaluesthatweresuppliedwithyourkitmyvaryslightlyfromtheonethatI’musinginthediagrambutthatisokayaslongasthereareinarangeof220to560ohms.
TheTrafficLightThebasictrafficlightthatweseeoutintherealworldisaverysimpledevicethathas3lights,red,amberandgreen,withonesetfacingthenorthboundtraffic,onesetfacingtheeastboundtraffic,onesetfacingthesouthboundtrafficandasetfacingthewestboundtraffic.Inmostcasestheeastboundandwestboundtrafficlightsetsworkinginthesamepattern.Aswellthesouthboundandnorthboundtrafficlightsetsworkinginthesamepattern.Wecancreateasimplelittlecharttodisplaythispatternandmakeiteasiertounderstand.InthechartIusedNSforNorth/SouthandEWforEast/West.AlsoIaddedanextrarowatthebottomofthechartsothatIcouldusethisforthepinassignmentsonmyArduinoUno.
Step
NSGreen
NSAm
ber
NSRed
EWGreen
EWAmber
EWRed
Time
1 On Off Off Off Off On 25sec.2 Off On Off Off Off On 7sec.3 Off Off On Off Off On 1sec.4 Off Off On On Off Off 22sec.5 Off Off On Off On Off 6sec.6 Off Off On Off Off On 1sec.
UnoPin 7 8 9 10 11 12
Asfarasthesketchgoesthisisjustandextendedversionofthesketchweusedforthegradecrossingflasheranduses6outputstorunalloftheLEDs.BesuretoassignpinModeanddigitalWriteforeachLEDinyoursketch.Oncecompleteyoushouldhaveasketchthatlookssimilartomineshownbelow.
TheFritzingorwiringdiagramshouldlooksimilartotheimagebelow.
ConclusionThisshouldhelpyoucreateafewmoresketchesfromitemsthatyouseeoutoneverydaylife.Asanexampleifyoumodelrailroadlayouthasawharfmaybeacoupleofnavigationlightsatornearthedockshouldbeadded.Youcouldresearchtheflashingpatternandcolourrequiredforeachoftheselights.Alsothereareotherwarninglightsthathavepatternsthatarenotsimpleon/offcyclesuchasthered/bluelightsofapolicecar.HavefunandcheckoutthevideoandwewillcontinuethisadventureinthenextissueofTheCanadian!