[{"data":1,"prerenderedAt":3290},["ShallowReactive",2],{"learn-hub-tutorials":3},[4,696,1126,1547,1844,2123,2386,2695,3018],{"id":5,"title":6,"body":7,"description":674,"draft":677,"duration":678,"extension":679,"image":680,"kit":681,"language":685,"level":686,"meta":687,"navigation":688,"path":689,"pdf":690,"platform":691,"seo":692,"stem":693,"youtube":694,"__hash__":695},"tutorials\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002Findex.md","MicroFit - Your very own Step Counter",{"type":8,"value":9,"toc":673},"minimark",[10],[11,12,13,87,93,100,161,192,234,261,307,347,392,442,483,503,547,573],"tutorial-steps",{},[14,15,17,27,39,42],"step",{"title":16},"Overview",[18,19,20,21,26],"p",{},"Ever wondered how a smartwatch or fitness band counts your steps? In this project, you're going to build your very own step counter using a ",[22,23,25],"g",{"slug":24},"micro-bit","micro:bit","!",[18,28,29,30,33,34,38],{},"Inside your micro:bit is a clever little sensor called an ",[22,31,32],{"slug":32},"accelerometer",". It can feel when the micro:bit moves. We'll use it to spot every step you take, add them up, and show the total on the ",[22,35,37],{"slug":36},"led-matrix","LED matrix"," (the grid of lights on the front).",[18,40,41],{},"The best bit? When you're done, you'll have a real working fitness tracker you can pop on and take outside. Don't worry if something doesn't work first time, that's all part of coding. Let's give it a go!",[43,44,47,53],"callout",{"color":45,"icon":46},"green","🎯",[18,48,49],{},[50,51,52],"strong",{},"What you'll learn",[54,55,56,63,66,69,72,79],"ul",{},[57,58,59,60],"li",{},"Make and use your own ",[22,61,62],{"slug":62},"variable",[57,64,65],{},"Use the micro:bit's shake sensor to spot movement",[57,67,68],{},"Show a number on the grid of lights",[57,70,71],{},"Use the buttons to control your project",[57,73,74,75],{},"Use a ",[22,76,78],{"slug":77},"while-loop","while loop",[57,80,81,82,86],{},"Make decisions with ",[22,83,85],{"slug":84},"if-statement","if statement","s",[14,88,90],{"title":89},"What you'll need",[91,92],"what-youll-need",{},[14,94,96],{"title":95},"Key words",[97,98],"key-words",{"terms":99},"variable,while-loop,if-statement,accelerometer,led-matrix,button",[14,101,103,138,145,155],{"title":102},"Set up your micro:bit EduBlocks Editor",[104,105,106,109,120],"ol",{},[57,107,108],{},"Open your web browser. We recommend Google Chrome or Microsoft Edge.",[57,110,111,112,119],{},"In the address bar type ",[113,114,118],"a",{"href":115,"rel":116},"https:\u002F\u002Fapp.edublocks.org\u002F",[117],"nofollow","app.edublocks.org",".",[57,121,122,123,126,127,129,130,133,134,137],{},"Under ",[50,124,125],{},"Create New Project",", select ",[50,128,25],{},". Name your project ",[50,131,132],{},"MicroFit",", and make sure ",[50,135,136],{},"block"," is selected under type.",[18,139,140],{},[141,142],"img",{"alt":143,"src":144},"Creating a new EduBlocks project","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FProjectCreation.webp",[104,146,148],{"start":147},4,[57,149,150,151,154],{},"Select ",[50,152,153],{},"Create"," to open the micro:bit editor.",[18,156,157],{},[141,158],{"alt":159,"src":160},"The EduBlocks code area","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FCodeArea.webp",[14,162,164,183,186],{"title":163},"Import the MicroPython library",[18,165,150,166,169,170,173,174,178,179,182],{},[50,167,168],{},"Basic",", then ",[50,171,172],{},"Imports",", then snap a ",[175,176,177],"code",{},"from microbit import *"," block onto the ",[175,180,181],{},"#start code here"," block.",[18,184,185],{},"This imports the micro:bit library into EduBlocks so we can use all the micro:bit's functions.",[18,187,188],{},[141,189],{"alt":190,"src":191},"Importing the MicroPython library","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FS1_ImportingPythonLibrary.webp",[14,193,195,219,228],{"title":194},"Set steps to 0",[104,196,197,210],{},[57,198,150,199,202,203,206,207,119],{},[50,200,201],{},"Variables",", choose ",[50,204,205],{},"Create a Variable",", and name it ",[50,208,209],{},"steps",[57,211,212,213,216,217,182],{},"Snap a ",[175,214,215],{},"steps = 0"," block to the ",[175,218,177],{},[18,220,221,222,224,225,227],{},"This makes a ",[22,223,62],{"slug":62}," called ",[50,226,209],{}," and starts it at zero.",[18,229,230],{},[141,231],{"alt":232,"src":233},"Setting steps to zero","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FS2_SettingStepsToZero.webp",[14,235,237,249,255],{"title":236},"Create a while True loop",[18,238,150,239,169,241,173,244,178,247,182],{},[50,240,168],{},[50,242,243],{},"Loops",[175,245,246],{},"while True:",[175,248,215],{},[18,250,251,252,254],{},"This ",[22,253,78],{"slug":77}," gives us a space to put code that repeats forever.",[18,256,257],{},[141,258],{"alt":259,"src":260},"Creating a while True loop","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FS3_CreatingWhileLoop.webp",[14,262,264,296,301],{"title":263},"Detect a shake",[104,265,266,280],{},[57,267,150,268,169,270,273,274,277,278,182],{},[50,269,168],{},[50,271,272],{},"Logic",", then drag an ",[175,275,276],{},"if True:"," block inside the ",[175,279,246],{},[57,281,150,282,285,286,178,289,292,293,119],{},[50,283,284],{},"Accelerometer",", then snap an ",[175,287,288],{},"accelerometer.was_gesture(\"shake\")",[175,290,291],{},"if"," block where it says ",[50,294,295],{},"True",[18,297,251,298,300],{},[22,299,85],{"slug":84}," runs its code only when the micro:bit feels a shake.",[18,302,303],{},[141,304],{"alt":305,"src":306},"Creating the shake function","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FS4_CreatingTheShakeFunction.webp",[14,308,310,338,341],{"title":309},"Increase the steps",[104,311,312,321],{},[57,313,150,314,173,316,277,318,182],{},[50,315,201],{},[175,317,215],{},[175,319,320],{},"if accelerometer.was_gesture(\"shake\"):",[57,322,323,324,327,328,331,332,327,335,119],{},"Change the ",[50,325,326],{},"="," to ",[50,329,330],{},"+="," and the ",[50,333,334],{},"0",[50,336,337],{},"1",[18,339,340],{},"Now every detected shake adds one to your step count.",[18,342,343],{},[141,344],{"alt":345,"src":346},"Increasing the steps","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FS5_IncreasingStepsBy.webp",[14,348,350,383,386],{"title":349},"Pause the code",[18,351,150,352,169,354,173,357,360,361,364,365,367,368,370,371,373,374,376,377,327,380,119],{},[50,353,168],{},[50,355,356],{},"Statements",[175,358,359],{},"sleep (1000)"," block ",[50,362,363],{},"below"," the ",[175,366,320],{}," block, lined up with the ",[175,369,291],{}," (inside the ",[175,372,246],{}," loop, but not inside the ",[175,375,291],{},"). Change ",[50,378,379],{},"1000",[50,381,382],{},"500",[18,384,385],{},"This pauses for half a second so the loop has time to notice the button press we'll add next.",[18,387,388],{},[141,389],{"alt":390,"src":391},"Pausing the code","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FS6_PausingTheCode.webp",[14,393,395,429,436],{"title":394},"Reset the steps with button A",[104,396,397,408,420],{},[57,398,150,399,169,401,285,403,178,405,182],{},[50,400,168],{},[50,402,272],{},[175,404,276],{},[175,406,407],{},"sleep (500)",[57,409,150,410,173,413,178,416,292,418,119],{},[50,411,412],{},"Buttons",[175,414,415],{},"button_a.was_pressed()",[175,417,291],{},[50,419,295],{},[57,421,150,422,173,424,277,426,182],{},[50,423,201],{},[175,425,215],{},[175,427,428],{},"if button_a.was_pressed():",[18,430,431,432,435],{},"Pressing ",[22,433,434],{"slug":434},"button"," A now resets your step count back to zero.",[18,437,438],{},[141,439],{"alt":440,"src":441},"Resetting steps to zero","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FS7_ResettingSteps.webp",[14,443,445,471,477],{"title":444},"Show the number of steps",[104,446,447,458],{},[57,448,150,449,173,452,455,456,182],{},[50,450,451],{},"Display",[175,453,454],{},"display.scroll (\"Hello World\")"," block just below the ",[175,457,428],{},[57,459,150,460,173,462,178,464,467,468,119],{},[50,461,201],{},[175,463,209],{},[175,465,466],{},"display.scroll"," block, over the words ",[50,469,470],{},"\"Hello World\"",[18,472,473,474,476],{},"This block sits inside the loop but not inside the button A block, so your steps scroll across the ",[22,475,37],{"slug":36}," all the time, not just when you press A.",[18,478,479],{},[141,480],{"alt":481,"src":482},"Displaying the number of steps","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FS8_DisplayingSteps.webp",[14,484,486],{"title":485},"Downloading the Code",[104,487,488,491,497],{},[57,489,490],{},"Connect the micro:bit to the computer with the micro USB cable.",[57,492,150,493,496],{},[50,494,495],{},"Connect"," and follow the on-screen prompts to pair the micro:bit with your web browser.",[57,498,150,499,502],{},[50,500,501],{},"Download"," to send the code to your micro:bit.",[14,504,506,511,514,534,540,544],{"title":505},"Run it and Watch",[507,508,510],"h3",{"id":509},"in-the-web-browser","In the web browser",[18,512,513],{},"EduBlocks has a built-in micro:bit simulator, handy if you haven't got a micro:bit to hand.",[104,515,516,522,528],{},[57,517,518,519,119],{},"On the right-hand side of the screen, select ",[50,520,521],{},"Simulator",[57,523,524,525,119],{},"From the accelerometer menu below the simulator, select ",[50,526,527],{},"Shake",[57,529,150,530,533],{},[50,531,532],{},"Send",". This simulates a shake and shows a number on the simulated micro:bit.",[18,535,536],{},[141,537],{"alt":538,"src":539},"The EduBlocks simulator","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002FSimulatorPreview.webp",[507,541,543],{"id":542},"on-a-real-microbit","On a real micro:bit",[18,545,546],{},"Once your code's downloaded, give the micro:bit a shake. Each shake bumps your step count up by one on the LED matrix. Pop a battery pack on, attach it to your wrist or ankle, and head outside to watch your steps climb.",[14,548,550],{"title":549},"Try it yourself",[551,552,553],"try-it",{},[18,554,555,558,559,561,562,564,565,568,569,572],{},[50,556,557],{},"Challenge:"," Set yourself a step goal! Add another ",[175,560,291],{}," block inside your ",[175,563,246],{}," loop that checks when ",[175,566,567],{},"steps >= 20",". When you hit it, use a ",[175,570,571],{},"display.show"," block to show a happy face to celebrate, then press button A to reset and go again.",[14,574,576],{"title":575},"Stuck? Quick fixes",[577,578,579,592],"table",{},[580,581,582],"thead",{},[583,584,585,589],"tr",{},[586,587,588],"th",{},"Problem",[586,590,591],{},"Try this",[593,594,595,611,626,645,657,665],"tbody",{},[583,596,597,601],{},[598,599,600],"td",{},"The number doesn't go up when I shake it",[598,602,603,604,607,608,610],{},"Check your ",[175,605,606],{},"steps += 1"," block is inside the ",[175,609,320],{}," block. Give the micro:bit one firm, clear shake.",[583,612,613,616],{},[598,614,615],{},"The count jumps up by lots at once",[598,617,618,619,622,623,625],{},"A big wobble can look like several shakes. Try one single, definite shake, and check the ",[175,620,621],{},"sleep(500)"," block is inside your ",[175,624,246],{}," loop so each shake has time to register.",[583,627,628,631],{},[598,629,630],{},"Nothing shows on the LED matrix",[598,632,633,634,607,636,638,639,641,642,644],{},"Make sure the ",[175,635,209],{},[175,637,466],{}," block (in place of \"Hello World\"), and that ",[175,640,466],{}," is inside your ",[175,643,246],{}," loop.",[583,646,647,650],{},[598,648,649],{},"Button A won't reset the steps",[598,651,652,653,607,655,182],{},"Check the ",[175,654,215],{},[175,656,428],{},[583,658,659,662],{},[598,660,661],{},"The number doesn't update while I keep shaking",[598,663,664],{},"Don't worry, it's still counting! The micro:bit can't show the new number while it's busy scrolling the last one. Stop shaking for a moment and the latest total will scroll across.",[583,666,667,670],{},[598,668,669],{},"My code won't download to the micro:bit",[598,671,672],{},"Use a data USB cable (not a charge-only one), make sure the micro:bit is paired, and try a different USB port.",{"title":674,"searchDepth":675,"depth":675,"links":676},"",2,[],false,"10 mins","md","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002Fmicrofit-cover.png",[682,25,683,684],"The micro:bit EduBlocks editor","micro USB cable","battery pack for the micro:bit (optional)","edublocks","Beginner",{},true,"\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit","\u002Flearn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002Fmicrofit.pdf","microbit",{"title":6,"description":674},"learn\u002Fmicrobit\u002Fedublocks\u002Fmicrofit\u002Findex",null,"tzU_uk-YKS70h5kDkgwOa0ZIphgODlCg80d72CF0YJo",{"id":697,"title":698,"body":699,"description":674,"draft":677,"duration":678,"extension":679,"image":1116,"kit":1117,"language":1119,"level":686,"meta":1120,"navigation":688,"path":1121,"pdf":1122,"platform":691,"seo":1123,"stem":1124,"youtube":694,"__hash__":1125},"tutorials\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002Findex.md","MicroFit: Your very own Step Counter",{"type":8,"value":700,"toc":1114},[701],[11,702,703,734,738,743,804,843,875,915,941,1001,1025,1042],{},[14,704,705,709,715,717],{"title":16},[18,706,20,707,26],{},[22,708,25],{"slug":24},[18,710,29,711,33,713,38],{},[22,712,32],{"slug":32},[22,714,37],{"slug":36},[18,716,41],{},[43,718,719,723],{"color":45,"icon":46},[18,720,721],{},[50,722,52],{},[54,724,725,728,731],{},[57,726,727],{},"How a light sensor measures the light around it",[57,729,730],{},"How to use an if\u002Felse block to make a decision",[57,732,733],{},"How to switch an RGB LED on and off automatically",[14,735,736],{"title":89},[91,737],{},[14,739,740],{"title":95},[97,741],{"terms":742},"variable,accelerometer,led-matrix,forever-loop,button",[14,744,746,750,771,777,781],{"title":745},"Navigating to the MakeCode Editor",[507,747,749],{"id":748},"on-a-computer","On a Computer",[104,751,752,755,763],{},[57,753,754],{},"Open your favourite web browser. We recommend either Google Chrome or Microsoft Edge.",[57,756,757,758,119],{},"In the Address bar type ",[113,759,762],{"href":760,"rel":761},"https:\u002F\u002Fmakecode.microbit.org\u002F#",[117],"makecode.microbit.org",[57,764,150,765,768,769,119],{},[50,766,767],{},"New Project"," and give it the name ",[50,770,132],{},[18,772,773],{},[141,774],{"alt":775,"src":776},"The MakeCode code area","\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002FCodeArea.webp",[507,778,780],{"id":779},"on-a-tablet-or-phone","On a Tablet or Phone",[104,782,783,792,797],{},[57,784,785,786,789,790,119],{},"Open the ",[50,787,788],{},"micro:bit app",". If you don't have the app yet you can download it from your devices app store by searching for ",[50,791,25],{},[57,793,150,794,119],{},[50,795,796],{},"Create Code",[57,798,150,799,801,802,119],{},[50,800,767],{}," and name it ",[50,803,132],{},[14,805,807,837],{"title":806},"Set up the Code Area",[104,808,809,820,830],{},[57,810,811,812,815,816,819],{},"Select the ",[175,813,814],{},"on start"," block and drop it on the ",[50,817,818],{},"bin"," icon to delete it.",[57,821,150,822,825,826,829],{},[50,823,824],{},"Input",". Select a ",[175,827,828],{},"on shake"," block and drop it within the code area.",[57,831,150,832,825,834,829],{},[50,833,824],{},[175,835,836],{},"on button A pressed",[18,838,839],{},[141,840],{"alt":841,"src":842},"Setting up the code area","\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002FS1_SettingUpCodeArea.webp",[14,844,846,864,869],{"title":845},"Change Steps by 1",[104,847,848,857],{},[57,849,150,850,202,852,206,855,119],{},[50,851,201],{},[50,853,854],{},"Make a Variable",[50,856,209],{},[57,858,212,859,277,862,182],{},[175,860,861],{},"change steps by 1",[175,863,828],{},[18,865,866,867,119],{},"Every time the micro:bit detects a shake, it adds one to your steps ",[22,868,62],{"slug":62},[18,870,871],{},[141,872],{"alt":873,"src":874},"Adding change steps by 1","\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002FS2_ChangeStepsBy.webp",[14,876,877,900,909],{"title":444},[104,878,879,889],{},[57,880,150,881,173,883,277,886,182],{},[50,882,168],{},[175,884,885],{},"show number",[175,887,888],{},"forever",[57,890,150,891,173,893,178,895,897,898,119],{},[50,892,201],{},[175,894,209],{},[175,896,885],{}," block, where it says ",[50,899,334],{},[18,901,251,902,906,907],{},[22,903,905],{"slug":904},"forever-loop","forever loop"," keeps running and shows your step count on the ",[22,908,37],{"slug":36},[18,910,911],{},[141,912],{"alt":913,"src":914},"Showing the number of steps","\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002FS3_ShowNumberOfSteps.webp",[14,916,918,927,936],{"title":917},"Reset the steps to zero",[18,919,150,920,173,922,277,925,182],{},[50,921,201],{},[175,923,924],{},"set steps to 0",[175,926,836],{},[18,928,929,930,932,933,935],{},"Now, pressing ",[22,931,434],{"slug":434}," A on the micro:bit resets your step ",[22,934,62],{"slug":62}," back to zero.",[18,937,938],{},[141,939],{"alt":232,"src":940},"\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002FS4_SetStepsToZero.webp",[14,942,944,948,979,985,989,998],{"title":943},"Downloading Your Code",[507,945,947],{"id":946},"using-a-computer","Using a Computer",[104,949,950,958,963,966,975],{},[57,951,811,952,955,956,119],{},[50,953,954],{},"three dots"," next to ",[50,957,501],{},[57,959,150,960,119],{},[50,961,962],{},"Connect Device",[57,964,965],{},"A pop-up will show you how to connect the micro:bit to the computer. Keep following the on-screen instructions.",[57,967,150,968,971,972,974],{},[50,969,970],{},"BBC micro:bit XXX"," and select ",[50,973,495],{},". The XXX is your own micro:bit's name, so don't worry if it looks a little different.",[57,976,150,977,119],{},[50,978,501],{},[18,980,981],{},[141,982],{"alt":983,"src":984},"Downloading your code","\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002FDownloadingCode.webp",[507,986,988],{"id":987},"using-a-tablet-or-phone","Using a tablet or phone",[104,990,991,995],{},[57,992,150,993,119],{},[50,994,501],{},[57,996,997],{},"Follow the on-screen instructions to pair the micro:bit with the micro:bit app.",[18,999,1000],{},"Once you've finished the on-screen steps, your code downloads to your micro:bit.",[14,1002,1003,1006,1019],{"title":505},[18,1004,1005],{},"Shake the micro:bit to watch your steps go up. Pop a battery pack on, attach the micro:bit to your wrist or ankle, and head outside to see how many steps you can rack up!",[18,1007,1008,1011,1012,955,1015,1018],{},[50,1009,1010],{},"Dont Have a microbit"," We can test it on the MakeCode editor by selecting the ",[50,1013,1014],{},"white dot",[50,1016,1017],{},"shake"," on the micro:bit simulator and watch our steps counter climb everytime we select the dot.",[18,1020,1021],{},[141,1022],{"alt":1023,"src":1024},"Shake button on the micro:bit Simulator","\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002FSimDemo.webp",[14,1026,1027],{"title":549},[551,1028,1029],{},[18,1030,1031,1033,1034,277,1036,1038,1039,1041],{},[50,1032,557],{}," Set yourself a step goal! Add an ",[175,1035,291],{},[175,1037,888],{}," loop to check when ",[175,1040,209],{}," reaches a target, like 20. When you hit it, make the micro:bit show a happy face or play a sound to celebrate, then press button A to reset and go again.",[14,1043,1044],{"title":575},[577,1045,1046,1054],{},[580,1047,1048],{},[583,1049,1050,1052],{},[586,1051,588],{},[586,1053,591],{},[593,1055,1056,1066,1073,1090,1098,1108],{},[583,1057,1058,1060],{},[598,1059,600],{},[598,1061,603,1062,607,1064,610],{},[175,1063,861],{},[175,1065,828],{},[583,1067,1068,1070],{},[598,1069,615],{},[598,1071,1072],{},"A big wobble can look like several shakes. Try one single, definite shake each time.",[583,1074,1075,1077],{},[598,1076,630],{},[598,1078,633,1079,1081,1082,1084,1085,1087,1088,182],{},[175,1080,209],{}," variable is snapped inside the ",[175,1083,885],{}," block, and that ",[175,1086,885],{}," is inside the ",[175,1089,888],{},[583,1091,1092,1095],{},[598,1093,1094],{},"The number doesn't change straight away when I shake fast",[598,1096,1097],{},"That's okay, it's still counting! The micro:bit can't show the new number while the last one is still scrolling. Stop shaking for a moment and your latest total will pop up.",[583,1099,1100,1102],{},[598,1101,649],{},[598,1103,652,1104,607,1106,182],{},[175,1105,924],{},[175,1107,836],{},[583,1109,1110,1112],{},[598,1111,669],{},[598,1113,672],{},{"title":674,"searchDepth":675,"depth":675,"links":1115},[],"\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002Fmicrofit-cover.png",[1118,25,683,684],"The micro:bit MakeCode editor","makecode",{},"\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit","\u002Flearn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002Fmicrofit.pdf",{"title":698,"description":674},"learn\u002Fmicrobit\u002Fmakecode\u002Fmicrofit\u002Findex","4490CD1NuIk6usPyUn6srLDibuRYMQHG40HNn13mwD8",{"id":1127,"title":6,"body":1128,"description":674,"draft":677,"duration":678,"extension":679,"image":1537,"kit":1538,"language":1540,"level":686,"meta":1541,"navigation":688,"path":1542,"pdf":1543,"platform":691,"seo":1544,"stem":1545,"youtube":694,"__hash__":1546},"tutorials\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002Findex.md",{"type":8,"value":1129,"toc":1535},[1130],[11,1131,1132,1172,1176,1180,1230,1257,1276,1309,1327,1369,1385,1413,1438,1460],{},[14,1133,1134,1138,1144,1146],{"title":16},[18,1135,20,1136,26],{},[22,1137,25],{"slug":24},[18,1139,29,1140,33,1142,38],{},[22,1141,32],{"slug":32},[22,1143,37],{"slug":36},[18,1145,41],{},[43,1147,1148,1152],{"color":45,"icon":46},[18,1149,1150],{},[50,1151,52],{},[54,1153,1154,1158,1160,1162,1164,1168],{},[57,1155,59,1156],{},[22,1157,62],{"slug":62},[57,1159,65],{},[57,1161,68],{},[57,1163,71],{},[57,1165,74,1166],{},[22,1167,78],{"slug":77},[57,1169,81,1170,86],{},[22,1171,85],{"slug":84},[14,1173,1174],{"title":89},[91,1175],{},[14,1177,1178],{"title":95},[97,1179],{"terms":99},[14,1181,1183,1208,1214,1224],{"title":1182},"Set up your micro:bit Python Editor",[104,1184,1185,1187,1196,1201],{},[57,1186,108],{},[57,1188,111,1189,119],{},[50,1190,1191],{},[113,1192,1195],{"href":1193,"rel":1194},"https:\u002F\u002Fpython.microbit.org",[117],"python.microbit.org",[57,1197,1198,1199,119],{},"Give your project a name: select the project name box at the top of the editor and type ",[50,1200,132],{},[57,1202,1203,1204,1207],{},"Close the left-hand panel by selecting the ",[50,1205,1206],{},"arrow"," pointing to the left.",[18,1209,1210],{},[141,1211],{"alt":1212,"src":1213},"Closing the left-hand panel","\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002FClosingPanel.webp",[104,1215,1217],{"start":1216},5,[57,1218,1219,1220,1223],{},"Delete the code on lines ",[50,1221,1222],{},"5 to 9"," in the main code area.",[18,1225,1226],{},[141,1227],{"alt":1228,"src":1229},"The Python editor code area","\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002FCodeArea.webp",[14,1231,1233,1251],{"title":1232},"Create a variable",[18,1234,1235,1236,1238,1239,224,1241,1243,1244,1246,1247,1250],{},"On line 3, type ",[175,1237,215],{}," to create a ",[22,1240,62],{"slug":62},[50,1242,209],{},", set to ",[50,1245,334],{}," for when the code starts. Press ",[50,1248,1249],{},"Enter"," to make a new line.",[18,1252,1253],{},[141,1254],{"alt":1255,"src":1256},"Creating the steps variable","\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002FS1_CreatingVariable.webp",[14,1258,1259,1271],{"title":236},[18,1260,1261,1262,1264,1265,1267,1268,1270],{},"Type ",[175,1263,246],{}," and press ",[50,1266,1249],{},". This creates a ",[22,1269,78],{"slug":77},", so anything inside it runs while the condition stays true. Notice your cursor automatically indents, that's how Python shows what's inside the loop.",[18,1272,1273],{},[141,1274],{"alt":259,"src":1275},"\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002FS2_CreatingWhileLoop.webp",[14,1277,1278,1292,1303],{"title":263},[104,1279,1280,1288],{},[57,1281,1261,1282,1264,1285,1287],{},[175,1283,1284],{},"if accelerometer.was_gesture('shake'):",[50,1286,1249],{},". The cursor indents again.",[57,1289,1261,1290,119],{},[175,1291,606],{},[18,1293,251,1294,1296,1297,1299,1300,1302],{},[22,1295,85],{"slug":84}," adds ",[50,1298,337],{}," to your ",[50,1301,209],{}," variable every time the micro:bit detects a shake.",[18,1304,1305],{},[141,1306],{"alt":1307,"src":1308},"Detecting a shake","\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002FS3_DetectingAShake.webp",[14,1310,1311,1322],{"title":349},[18,1312,1261,1313,1315,1316,1318,1319,1321],{},[175,1314,621],{},". This pauses the code for half a second, giving the micro:bit time to do other things, like check for the button press we'll add next. Press ",[50,1317,1249],{},", then delete the indent so the cursor lines back up with the ",[175,1320,1284],{}," line.",[18,1323,1324],{},[141,1325],{"alt":390,"src":1326},"\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002FS4_PausingTheCode.webp",[14,1328,1329,1363],{"title":394},[104,1330,1331,1341,1356],{},[57,1332,1261,1333,1264,1335,1337,1338,1340],{},[175,1334,428],{},[50,1336,1249],{},". This detects a ",[22,1339,434],{"slug":434}," press, and the cursor indents.",[57,1342,1261,1343,1345,1346,1348,1349,1351,1352,1355],{},[175,1344,215],{}," to reset the ",[50,1347,209],{}," variable back to ",[50,1350,334],{}," when button ",[50,1353,1354],{},"A"," is pressed.",[57,1357,1358,1359,1318,1361,1321],{},"Press ",[50,1360,1249],{},[175,1362,428],{},[18,1364,1365],{},[141,1366],{"alt":1367,"src":1368},"Resetting the steps to zero","\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002FS5_ResettingSteps.webp",[14,1370,1371,1380],{"title":444},[18,1372,1261,1373,1376,1377,1379],{},[175,1374,1375],{},"display.scroll(steps)",". This scrolls the number of steps across the ",[22,1378,37],{"slug":36}," on the front of the micro:bit.",[18,1381,1382],{},[141,1383],{"alt":481,"src":1384},"\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002FS6_DisplayingSteps.webp",[14,1386,1387,1408],{"title":943},[104,1388,1389,1391,1398,1403],{},[57,1390,490],{},[57,1392,811,1393,955,1395,119],{},[50,1394,954],{},[50,1396,1397],{},"Send to micro:bit",[57,1399,150,1400,1402],{},[50,1401,495],{}," and follow the on-screen prompts.",[57,1404,150,1405,1407],{},[50,1406,1397],{}," to download the code.",[18,1409,1410],{},[141,1411],{"alt":983,"src":1412},"\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002FDownloadingCode.webp",[14,1414,1415,1417,1427,1433,1435],{"title":505},[507,1416,510],{"id":509},[18,1418,1419,1420,1422,1423,1426],{},"The Python editor has a built-in micro:bit simulator, handy if you haven't got a micro:bit to hand. Below the simulator you'll see the ",[50,1421,1017],{}," function is already selected. Select the ",[50,1424,1425],{},"play"," button next to it to simulate a shake and show your step count on the LED matrix.",[18,1428,1429],{},[141,1430],{"alt":1431,"src":1432},"The Python editor simulator","\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002FSimulatorDemo.webp",[507,1434,543],{"id":542},[18,1436,1437],{},"Once your code's downloaded, give the micro:bit a shake and watch the step counter climb. Why not go further? Attach a battery pack, strap the micro:bit to you or pop it in your pocket, and head outside to see how many steps you can rack up.",[14,1439,1440],{"title":549},[551,1441,1442],{},[18,1443,1444,558,1446,1448,1449,1451,1452,1455,1456,1459],{},[50,1445,557],{},[175,1447,291],{}," statement inside your ",[175,1450,246],{}," loop that checks ",[175,1453,1454],{},"if steps >= 20:",". When you hit it, type ",[175,1457,1458],{},"display.show(Image.HAPPY)"," to show a happy face and celebrate, then press button A to reset and go again.",[14,1461,1462],{"title":575},[577,1463,1464,1472],{},[580,1465,1466],{},[583,1467,1468,1470],{},[586,1469,588],{},[586,1471,591],{},[593,1473,1474,1486,1497,1512,1518,1529],{},[583,1475,1476,1478],{},[598,1477,600],{},[598,1479,603,1480,1482,1483,1485],{},[175,1481,606],{}," line is indented inside the ",[175,1484,1284],{}," statement. Give the micro:bit one firm, clear shake.",[583,1487,1488,1490],{},[598,1489,615],{},[598,1491,618,1492,1494,1495,625],{},[175,1493,621],{}," line is inside your ",[175,1496,246],{},[583,1498,1499,1501],{},[598,1500,630],{},[598,1502,1503,1504,1506,1507,1509,1510,644],{},"Make sure you've typed ",[175,1505,1375],{}," with ",[175,1508,209],{}," inside the brackets, and that the line is indented inside your ",[175,1511,246],{},[583,1513,1514,1516],{},[598,1515,1094],{},[598,1517,1097],{},[583,1519,1520,1522],{},[598,1521,649],{},[598,1523,652,1524,1482,1526,1528],{},[175,1525,215],{},[175,1527,428],{}," statement.",[583,1530,1531,1533],{},[598,1532,669],{},[598,1534,672],{},{"title":674,"searchDepth":675,"depth":675,"links":1536},[],"\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002Fmicrofit-cover.png",[1539,25,683,684],"The micro:bit Python editor","python",{},"\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit","\u002Flearn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002Fmicrofit.pdf",{"title":6,"description":674},"learn\u002Fmicrobit\u002Fpython\u002Fmicrofit\u002Findex","p_3jg7SGKcFENlFKrxBMxq-YhNgUFCq2Z23TeC2Iv7s",{"id":1548,"title":1549,"body":1550,"description":674,"draft":677,"duration":678,"extension":679,"image":1830,"kit":1831,"language":694,"level":686,"meta":1836,"navigation":688,"path":1837,"pdf":1838,"platform":1839,"seo":1840,"stem":1841,"youtube":1842,"__hash__":1843},"tutorials\u002Flearn\u002Fpicobricks\u002Fautomatic-lighting\u002Findex.md","Automatic Lighting",{"type":8,"value":1551,"toc":1828},[1552],[11,1553,1554,1583,1587,1592,1622,1746,1757,1773],{},[14,1555,1556,1569],{"title":16},[18,1557,1558,1559,1563,1564,1568],{},"In this project we'll build our very own automatic light, just like the ones that switch themselves on when it gets dark. We'll use the ",[22,1560,1562],{"slug":1561},"light-sensor","Light Sensor"," to measure how bright it is around us. When it gets too dark, the ",[22,1565,1567],{"slug":1566},"rgb-led","RGB LED"," will switch on all by itself, and when it's bright again, it turns back off.",[43,1570,1571,1575],{"color":45,"icon":46},[18,1572,1573],{},[50,1574,52],{},[54,1576,1577,1579,1581],{},[57,1578,727],{},[57,1580,730],{},[57,1582,733],{},[14,1584,1585],{"title":89},[91,1586],{},[14,1588,1589],{"title":95},[97,1590],{"terms":1591},"light-sensor,rgb-led,forever-loop,if-statement,threshold",[14,1593,1595,1616],{"title":1594},"Set up your PicoBricks",[104,1596,1597,1606,1609],{},[57,1598,1599,1600,1605],{},"Open your favourite web browser. We recommend either Google Chrome or Microsoft Edge. Type ",[113,1601,1604],{"href":1602,"rel":1603},"http:\u002F\u002Fide.picobricks.com",[117],"ide.picobricks.com"," into the address bar.",[57,1607,1608],{},"Connect the PicoBricks board to your computer using the USB cable.",[57,1610,1611,1612,1615],{},"Connect the PicoBricks board to the Brick IDE by selecting the ",[50,1613,1614],{},"Connection"," button at the top of the code area.",[18,1617,1618],{},[141,1619],{"alt":1620,"src":1621},"The PicoBricks Brick IDE coding environment","\u002Flearn\u002Fpicobricks\u002Fautomatic-lighting\u002FCodingEnvironment.webp",[14,1623,1625,1740],{"title":1624},"Build the code",[104,1626,1627,1636,1645,1654,1666,1677,1692,1705,1721,1730],{},[57,1628,150,1629,1631,1632,1635],{},[50,1630,168],{},". Drop a ",[175,1633,1634],{},"PicoBricks"," block into the code area.",[57,1637,150,1638,1640,1641,216,1643,182],{},[50,1639,243],{},". Snap a ",[22,1642,888],{"slug":904},[175,1644,1634],{},[57,1646,150,1647,1640,1649,277,1652,182],{},[50,1648,168],{},[175,1650,1651],{},"Serial Print",[175,1653,888],{},[57,1655,150,1656,1640,1659,178,1662,292,1664,119],{},[50,1657,1658],{},"Bricks",[175,1660,1661],{},"Read Light Sensor",[175,1663,1651],{},[50,1665,1634],{},[57,1667,150,1668,1670,1671,216,1674,182],{},[50,1669,272],{},". Snap an ",[22,1672,1673],{"slug":84},"if else",[175,1675,1676],{},"Serial Print Read Light Sensor",[57,1678,150,1679,1670,1681,178,1683,1685,1686,1688,1689,119],{},[50,1680,272],{},[175,1682,326],{},[175,1684,291],{}," block, then change the ",[50,1687,326],{}," to a ",[50,1690,1691],{},">",[57,1693,150,1694,1696,1697,1699,1700,1702,1703,119],{},[50,1695,1658],{},". Add a ",[175,1698,1661],{}," block into the first blank space of the ",[175,1701,291],{}," block, before the ",[50,1704,1691],{},[57,1706,150,1707,1640,1710,1712,1713,1715,1716,327,1718,119],{},[50,1708,1709],{},"Math",[175,1711,334],{}," block into the space after the ",[50,1714,1691],{},", then change ",[50,1717,334],{},[50,1719,1720],{},"10,000",[57,1722,150,1723,1640,1725,277,1728,182],{},[50,1724,1567],{},[175,1726,1727],{},"Set RGB Led Colour",[175,1729,291],{},[57,1731,150,1732,1640,1734,277,1737,182],{},[50,1733,1567],{},[175,1735,1736],{},"Clear RGB Led Colour",[175,1738,1739],{},"else",[18,1741,1742],{},[141,1743],{"alt":1744,"src":1745},"The finished Automatic Lighting code","\u002Flearn\u002Fpicobricks\u002Fautomatic-lighting\u002FAutomaticLightingCode.webp",[14,1747,1748,1751],{"title":505},[18,1749,1750],{},"Now the code is finished, let's run it and check it works. Select the run button at the top of the code area. If it's daylight the RGB LED should be off. If it's night time, or if you cover the light sensor with your hand, the RGB LED will turn on.",[18,1752,1753],{},[141,1754],{"alt":1755,"src":1756},"Automatic Lighting demo","\u002Flearn\u002Fpicobricks\u002Fautomatic-lighting\u002FAutomaticLightingDemo.gif",[14,1758,1759],{"title":549},[551,1760,1761],{},[18,1762,1763,1765,1766,1768,1769,1772],{},[50,1764,557],{}," Can you make your night light more colourful? Try changing the ",[50,1767,1727],{}," block to a different colour, so your light glows blue, green or purple when it gets dark. Feeling brave? Add a ",[50,1770,1771],{},"Buzzer"," block so it gives a gentle beep the moment the light comes on.",[14,1774,1775],{"title":575},[577,1776,1777,1785],{},[580,1778,1779],{},[583,1780,1781,1783],{},[586,1782,588],{},[586,1784,591],{},[593,1786,1787,1797,1805,1813],{},[583,1788,1789,1792],{},[598,1790,1791],{},"The RGB LED won't turn on at all",[598,1793,1794,1795,182],{},"Cover the light sensor fully with your hand to make it really dark. If it still won't light up, your room might not get dark enough to push the reading past the cut-off, so try lowering the 10,000 value in your ",[175,1796,291],{},[583,1798,1799,1802],{},[598,1800,1801],{},"The RGB LED is always on",[598,1803,1804],{},"Your everyday room light is already reading above the cut-off. Try raising the 10,000 value so the light only comes on when it's properly dark.",[583,1806,1807,1810],{},[598,1808,1809],{},"Nothing happens when I press Run",[598,1811,1812],{},"Check the PicoBricks board is connected (the connection button at the top should show it's linked). Unplugging and replugging the USB cable often does the trick.",[583,1814,1815,1818],{},[598,1816,1817],{},"I can't see the light readings",[598,1819,633,1820,607,1822,1824,1825,1827],{},[175,1821,1651],{},[175,1823,888],{}," loop, with the ",[175,1826,1661],{}," block snapped into it.",{"title":674,"searchDepth":675,"depth":675,"links":1829},[],"\u002Flearn\u002Fpicobricks\u002Fautomatic-lighting\u002Fcover-automatic-lighting.png",[1832,1833,1834,1835],"PicoBricks Kit","PicoBricks Brick IDE","MicroUSB to USB cable","Laptop or tablet for coding",{},"\u002Flearn\u002Fpicobricks\u002Fautomatic-lighting","\u002Flearn\u002Fpicobricks\u002Fautomatic-lighting\u002Fautomatic-lighting.pdf","picobricks",{"title":1549,"description":674},"learn\u002Fpicobricks\u002Fautomatic-lighting\u002Findex","https:\u002F\u002Fyoutu.be\u002FzBP0ivO4ypg","E7U8gAnK2V1b7nSpq3kemKJHqKKpPHLKP5j3mW7rD-E",{"id":1845,"title":1846,"body":1847,"description":674,"draft":677,"duration":678,"extension":679,"image":2114,"kit":2115,"language":694,"level":686,"meta":2116,"navigation":688,"path":2117,"pdf":2118,"platform":1839,"seo":2119,"stem":2120,"youtube":2121,"__hash__":2122},"tutorials\u002Flearn\u002Fpicobricks\u002Fblinking-led\u002Findex.md","Blinking LED Project",{"type":8,"value":1848,"toc":2112},[1849],[11,1850,1851,1888,1892,1897,1917,2004,2024,2043],{},[14,1852,1853,1863,1874,1877],{"title":16},[18,1854,1855,1856,1859,1860,1862],{},"In computer programming, when learning a new coding language we typically create a ",[50,1857,1858],{},"Hello World"," project, which prints ",[50,1861,1858],{}," to the screen.",[18,1864,1865,1866,1868,1869,1873],{},"When working with robotics and physical computing, our ",[50,1867,1858],{}," project becomes a blinking ",[22,1870,1872],{"slug":1871},"led","LED"," (light-emitting diode).",[18,1875,1876],{},"Let's take a look at how we'd create this on the PicoBricks using the Brick IDE.",[43,1878,1879,1883],{"color":45,"icon":46},[18,1880,1881],{},[50,1882,52],{},[54,1884,1885],{},[57,1886,1887],{},"How to make an LED blink on and off",[14,1889,1890],{"title":89},[91,1891],{},[14,1893,1894],{"title":95},[97,1895],{":terms":1896},"led, forever-loop",[14,1898,1899,1912],{"title":1594},[104,1900,1901,1906,1908],{},[57,1902,1599,1903,1605],{},[113,1904,1604],{"href":1602,"rel":1905},[117],[57,1907,1608],{},[57,1909,1611,1910,1615],{},[50,1911,1614],{},[18,1913,1914],{},[141,1915],{"alt":1620,"src":1916},"\u002Flearn\u002Fpicobricks\u002Fblinking-led\u002FCodingEnvironment.webp",[14,1918,1919,1995,2001],{"title":1624},[104,1920,1921,1928,1937,1952,1968,1982],{},[57,1922,150,1923,825,1925,1927],{},[50,1924,168],{},[175,1926,1634],{}," block and drop it in the code area.",[57,1929,150,1930,825,1932,1934,1935,182],{},[50,1931,243],{},[175,1933,888],{}," block and snap it to the ",[175,1936,1634],{},[57,1938,150,1939,825,1941,1944,1945,1947,1948,1951],{},[50,1940,1658],{},[175,1942,1943],{},"Set Led"," block and snap it within the ",[175,1946,888],{}," block. It will be set to ",[50,1949,1950],{},"on"," by default.",[57,1953,150,1954,825,1956,1934,1959,1962,1963,327,1965,119],{},[50,1955,243],{},[175,1957,1958],{},"wait",[175,1960,1961],{},"Set Led on"," block. Change the ",[50,1964,337],{},[50,1966,1967],{},"0.5",[57,1969,150,1970,825,1972,1934,1974,1962,1977,327,1979,119],{},[50,1971,1658],{},[175,1973,1943],{},[175,1975,1976],{},"wait 0.5",[50,1978,1950],{},[50,1980,1981],{},"off",[57,1983,150,1984,825,1986,1934,1988,1962,1991,327,1993,119],{},[50,1985,243],{},[175,1987,1958],{},[175,1989,1990],{},"Set Led off",[50,1992,337],{},[50,1994,1967],{},[18,1996,1997],{},[141,1998],{"alt":1999,"src":2000},"The completed block code for the blinking LED","\u002Flearn\u002Fpicobricks\u002Fblinking-led\u002FCompletedCode.webp",[18,2002,2003],{},"We've now completed the code for our blinking LED.",[14,2005,2007,2015,2018],{"title":2006},"Run it and watch",[104,2008,2009],{},[57,2010,811,2011,2014],{},[50,2012,2013],{},"run"," button at the top of the code window.",[18,2016,2017],{},"Your LED should now blink on and off every half a second. 🎉",[18,2019,2020],{},[141,2021],{"alt":2022,"src":2023},"The LED blinking on and off every half a second","\u002Flearn\u002Fpicobricks\u002Fblinking-led\u002FBlinkingLED.gif",[14,2025,2026],{"title":549},[551,2027,2028],{},[18,2029,2030,2032,2033,2035,2036,2039,2040,2042],{},[50,2031,557],{}," Can you make your LED blink faster or slower? Try changing both ",[175,2034,1976],{}," blocks to a smaller number like ",[175,2037,2038],{},"0.1"," for a speedy flash, or a bigger number like ",[175,2041,337],{}," for a slow, sleepy blink. What happens if you give the two waits different numbers?",[14,2044,2045],{"title":575},[577,2046,2047,2055],{},[580,2048,2049],{},[583,2050,2051,2053],{},[586,2052,588],{},[586,2054,591],{},[593,2056,2057,2065,2082,2101],{},[583,2058,2059,2062],{},[598,2060,2061],{},"The LED isn't lighting up at all",[598,2063,2064],{},"Check the USB cable is pushed in properly at both ends, and make sure the Brick IDE shows it's connected to your PicoBricks board.",[583,2066,2067,2070],{},[598,2068,2069],{},"The blocks won't snap together",[598,2071,2072,2073,2075,2076,2078,2079,2081],{},"Make sure each block is dropped just inside the one above it. The ",[175,2074,1943],{}," and ",[175,2077,1958],{}," blocks need to sit inside the ",[175,2080,888],{}," loop, not below it.",[583,2083,2084,2087],{},[598,2085,2086],{},"The LED comes on but never turns off",[598,2088,2089,2090,2092,2093,2095,2096,2098,2099,182],{},"Check your second ",[175,2091,1943],{}," block is set to ",[50,2094,1981],{},", and that a ",[175,2097,1958],{}," block sits after each ",[175,2100,1943],{},[583,2102,2103,2106],{},[598,2104,2105],{},"Nothing happens when I press run",[598,2107,2108,2109,2111],{},"Try reconnecting the board, then press ",[50,2110,2013],{}," again. Unplugging the USB cable and plugging it back in often helps too.",{"title":674,"searchDepth":675,"depth":675,"links":2113},[],"\u002Flearn\u002Fpicobricks\u002Fblinking-led\u002Fcover-blink.png",[1832,1833,1834,1835],{},"\u002Flearn\u002Fpicobricks\u002Fblinking-led","\u002Flearn\u002Fpicobricks\u002Fblink-project\u002Fblink-project.pdf",{"title":1846,"description":674},"learn\u002Fpicobricks\u002Fblinking-led\u002Findex","https:\u002F\u002Fyoutu.be\u002FiaCOzFQv5NY","TP7wi7qCgj8J-JrrB6vHskJHxBFwfneUlINmA2p6gW0",{"id":2124,"title":2125,"body":2126,"description":674,"draft":677,"duration":2374,"extension":679,"image":2375,"kit":2376,"language":694,"level":686,"meta":2379,"navigation":688,"path":2380,"pdf":2381,"platform":1839,"seo":2382,"stem":2383,"youtube":2384,"__hash__":2385},"tutorials\u002Flearn\u002Fpicobricks\u002Fcontrolling-a-servo-motor\u002Findex.md","Controlling a Servo Motor",{"type":8,"value":2127,"toc":2372},[2128],[11,2129,2130,2162,2166,2171,2183,2211,2294,2309,2318],{},[14,2131,2132,2148],{"title":16},[18,2133,2134,2135,2139,2140,2144,2145,2147],{},"In this tutorial we're going to control a ",[22,2136,2138],{"slug":2137},"servo-motor","servo motor"," using the ",[22,2141,2143],{"slug":2142},"motor-controller","motor controller"," on the ",[22,2146,1634],{"slug":1839}," board.",[43,2149,2150,2154],{"color":45,"icon":46},[18,2151,2152],{},[50,2153,52],{},[54,2155,2156,2159],{},[57,2157,2158],{},"How to connect a servo motor to the PicoBricks through the motor controller.",[57,2160,2161],{},"How to control the servo motor through code.",[14,2163,2164],{"title":89},[91,2165],{},[14,2167,2168],{"title":95},[97,2169],{"terms":2170},"servo-motor,motor-controller,picobricks,forever-loop",[14,2172,2174,2177],{"title":2173},"Wire up the servo motor",[18,2175,2176],{},"Connect the servo motor to the top connector of the motor controller with the yellow wire on the left pin. There's also a jumper across three pins. Make sure it's set for the servo motor, which means the jumper should be pushed as far left as it can go.",[18,2178,2179],{},[141,2180],{"alt":2181,"src":2182},"Servo motor wiring diagram","\u002Flearn\u002Fpicobricks\u002Fcontrolling-a-servo-motor\u002Fwiring-diagram.webp",[14,2184,2185,2205],{"title":1594},[104,2186,2187,2189,2199],{},[57,2188,1608],{},[57,2190,2191,2192,971,2196,119],{},"Open your favourite web browser (we recommend Google Chrome or Microsoft Edge), go to ",[113,2193,1604],{"href":2194,"rel":2195},"https:\u002F\u002Fide.picobricks.com",[117],[50,2197,2198],{},"PicoBlockly",[57,2200,2201,2202,1615],{},"Connect the board to the coding environment by selecting the ",[50,2203,2204],{},"connect",[18,2206,2207],{},[141,2208],{"alt":2209,"src":2210},"The PicoBlockly coding environment","\u002Flearn\u002Fpicobricks\u002Fcontrolling-a-servo-motor\u002Fcoding-environment.webp",[14,2212,2213,2288],{"title":1624},[104,2214,2215,2222,2230,2252,2262,2281],{},[57,2216,150,2217,2219,2220,1635],{},[50,2218,168],{},". Drag a ",[175,2221,1634],{},[57,2223,150,2224,1640,2226,178,2228,182],{},[50,2225,243],{},[175,2227,888],{},[175,2229,1634],{},[57,2231,150,2232,1640,2235,2238,2239,327,2242,2245,2246,327,2249,119],{},[50,2233,2234],{},"Motor",[175,2236,2237],{},"Set Servo M1 Angle 180"," block inside the forever block. Change ",[50,2240,2241],{},"M1",[50,2243,2244],{},"M2",", and change ",[50,2247,2248],{},"180",[50,2250,2251],{},"90",[57,2253,150,2254,1640,2256,2258,2259,182],{},[50,2255,243],{},[175,2257,1958],{}," block under the ",[175,2260,2261],{},"Set Servo M2 Angle 90",[57,2263,150,2264,2266,2267,2258,2269,2272,2273,327,2275,2075,2277,327,2279,119],{},[50,2265,2234],{},". Add another ",[175,2268,2237],{},[175,2270,2271],{},"wait 1"," block. Change ",[50,2274,2241],{},[50,2276,2244],{},[50,2278,2248],{},[50,2280,334],{},[57,2282,150,2283,1640,2285,2287],{},[50,2284,243],{},[175,2286,1958],{}," block under the `Set Servo M2 Angle 0` block.",[18,2289,2290],{},[141,2291],{"alt":2292,"src":2293},"The completed servo motor code","\u002Flearn\u002Fpicobricks\u002Fcontrolling-a-servo-motor\u002Fcompleted-code.webp",[14,2295,2296,2303],{"title":505},[18,2297,2298,2299,2302],{},"Now the code's finished, let's run it. Select the ",[50,2300,2301],{},"Run"," button at the top of the code area. You should see the little arm on the servo motor move between 90 and 0 degrees.",[18,2304,2305],{},[141,2306],{"alt":2307,"src":2308},"The servo motor arm moving between 90 and 0 degrees","\u002Flearn\u002Fpicobricks\u002Fcontrolling-a-servo-motor\u002Fdemo.gif",[14,2310,2311],{"title":549},[551,2312,2313],{},[18,2314,2315,2317],{},[50,2316,557],{}," Can you make the arm wave? Try adding more `Set Servo` blocks with different angles (like 0, 45 and 90), with a `wait` block after each one. What happens if you make the `wait` times shorter? Does the arm move faster?",[14,2319,2320],{"title":575},[577,2321,2322,2330],{},[580,2323,2324],{},[583,2325,2326,2328],{},[586,2327,588],{},[586,2329,591],{},[593,2331,2332,2340,2348,2356,2364],{},[583,2333,2334,2337],{},[598,2335,2336],{},"The servo isn't moving at all",[598,2338,2339],{},"Check the servo is on the top connector with the yellow wire on the left pin, and that the USB cable is plugged in properly.",[583,2341,2342,2345],{},[598,2343,2344],{},"The servo twitches or buzzes but won't turn",[598,2346,2347],{},"Check the jumper is pushed fully to the left so it's set for the servo.",[583,2349,2350,2353],{},[598,2351,2352],{},"The code won't run",[598,2354,2355],{},"Make sure you pressed the connect button and your board is connected in PicoBlockly before pressing Run.",[583,2357,2358,2361],{},[598,2359,2360],{},"The arm only moves once, then stops",[598,2362,2363],{},"Check all your blocks are inside the forever loop so they keep repeating.",[583,2365,2366,2369],{},[598,2367,2368],{},"The arm moves to the wrong place",[598,2370,2371],{},"Check you changed M1 to M2 on every block, and that your angles are set to 90 and 0.",{"title":674,"searchDepth":675,"depth":675,"links":2373},[],"15 mins","\u002Flearn\u002Fpicobricks\u002Fcontrolling-a-servo-motor\u002Fservo-cover.png",[1634,2377,2378],"Servo motor","USB to MicroUSB cable",{},"\u002Flearn\u002Fpicobricks\u002Fcontrolling-a-servo-motor","\u002Flearn\u002Fpicobricks\u002Fcontrolling-a-servo-motor\u002Fcontrolling-a-servo-motor.pdf",{"title":2125,"description":674},"learn\u002Fpicobricks\u002Fcontrolling-a-servo-motor\u002Findex","https:\u002F\u002Fyoutu.be\u002FSVJ-3dk5TyU","im4RedqYYg08eFPm5MVHwKhelI505zhjb5GcPMRfOWQ",{"id":2387,"title":2388,"body":2389,"description":674,"draft":677,"duration":2374,"extension":679,"image":2685,"kit":2686,"language":694,"level":686,"meta":2688,"navigation":688,"path":2689,"pdf":2690,"platform":1839,"seo":2691,"stem":2692,"youtube":2693,"__hash__":2694},"tutorials\u002Flearn\u002Fpicobricks\u002Fdimmable-led\u002Findex.md","Dimmable LED",{"type":8,"value":2390,"toc":2683},[2391],[11,2392,2393,2417,2421,2426,2448,2589,2603,2620],{},[14,2394,2395,2406],{"title":16},[18,2396,2397,2398,331,2400,2144,2403,2405],{},"In this tutorial we're going to use the ",[22,2399,1567],{"slug":1566},[22,2401,2402],{"slug":2402},"potentiometer",[22,2404,1634],{"slug":1839}," board to make a dimmable lighting system.",[43,2407,2408,2412],{"color":45,"icon":46},[18,2409,2410],{},[50,2411,52],{},[54,2413,2414],{},[57,2415,2416],{},"How to control the RGB LED using the potentiometer.",[14,2418,2419],{"title":89},[91,2420],{},[14,2422,2423],{"title":89},[97,2424],{"terms":2425},"potentiometer,rgb-led,variable,forever-loop",[14,2427,2428,2443],{"title":1594},[104,2429,2430,2432,2439],{},[57,2431,1608],{},[57,2433,2191,2434,971,2437,119],{},[113,2435,1604],{"href":2194,"rel":2436},[117],[50,2438,2198],{},[57,2440,2201,2441,1615],{},[50,2442,2204],{},[18,2444,2445],{},[141,2446],{"alt":2209,"src":2447},"\u002Flearn\u002Fpicobricks\u002Fdimmable-led\u002Fcoding-environment.webp",[14,2449,2450,2583],{"title":1624},[104,2451,2452,2458,2465,2481,2490,2505,2517,2547,2556,2569],{},[57,2453,150,2454,2219,2456,1635],{},[50,2455,168],{},[175,2457,1634],{},[57,2459,150,2460,1640,2462,2464],{},[50,2461,243],{},[175,2463,888],{}," block onto the `PicoBricks` block.",[57,2466,150,2467,2469,2470,2473,2474,1640,2477,2480],{},[50,2468,201],{},". Select ",[50,2471,2472],{},"Create variable"," and type ",[50,2475,2476],{},"Colour",[175,2478,2479],{},"set Colour to"," block inside the forever block.",[57,2482,150,2483,1640,2485,178,2488,182],{},[50,2484,1709],{},[175,2486,2487],{},"round",[175,2489,2479],{},[57,2491,150,2492,1640,2494,178,2497,1685,2499,1688,2502,119],{},[50,2493,1709],{},[175,2495,2496],{},"1 + 1",[175,2498,2487],{},[50,2500,2501],{},"+",[50,2503,2504],{},"x",[57,2506,150,2507,1640,2509,178,2512,1702,2514,2516],{},[50,2508,1658],{},[175,2510,2511],{},"Read Potentiometer",[175,2513,2487],{},[50,2515,2504],{}," sign.",[57,2518,150,2519,2521,2522,178,2524,2526,2527,2529,2530,327,2532,2535,2536,327,2538,2541,2542,327,2544,119],{},[50,2520,1709],{},". Snap another ",[175,2523,2496],{},[175,2525,2487],{}," block, after the ",[50,2528,2504],{},". Change the first ",[50,2531,337],{},[50,2533,2534],{},"255",", the ",[50,2537,2501],{},[50,2539,2540],{},"÷"," and the remaining ",[50,2543,337],{},[50,2545,2546],{},"65535",[57,2548,150,2549,1640,2551,2258,2554,182],{},[50,2550,1567],{},[175,2552,2553],{},"Set RGB Led Colour R 255 G 255 B 255",[175,2555,2479],{},[57,2557,150,2558,1640,2560,2562,2563,2566,2567,182],{},[50,2559,201],{},[175,2561,2476],{}," block into the ",[50,2564,2565],{},"R"," value of the ",[175,2568,1727],{},[57,2570,2571,2572,2575,2576,2075,2579,2582],{},"Do the same as ",[50,2573,2574],{},"step 9"," for the ",[50,2577,2578],{},"G",[50,2580,2581],{},"B"," values.",[18,2584,2585],{},[141,2586],{"alt":2587,"src":2588},"The completed dimmable LED code","\u002Flearn\u002Fpicobricks\u002Fdimmable-led\u002Fcompleted-code.webp",[14,2590,2591,2597],{"title":505},[18,2592,2593,2594,2596],{},"Now the code's finished, let's test it. Select the ",[50,2595,2301],{}," button at the top of the code area. Turn the potentiometer to see the LED get brighter or dimmer, right down until it goes out, depending on which way you turn it.",[18,2598,2599],{},[141,2600],{"alt":2601,"src":2602},"The dimmable LED fading up and down as the potentiometer turns","\u002Flearn\u002Fpicobricks\u002Fdimmable-led\u002Fdemo.gif",[14,2604,2605],{"title":549},[551,2606,2607],{},[18,2608,2609,2611,2612,2075,2614,2616,2617,2619],{},[50,2610,557],{}," Can you make your dial control just one colour? Try setting the ",[50,2613,2578],{},[50,2615,2581],{}," values to `0` and leave only the ",[50,2618,2565],{}," value linked to the potentiometer, so your knob fades a red glow from bright to off. Then have a go at swapping it to just green, or just blue. What happens if you mix two colours together?",[14,2621,2622],{"title":575},[577,2623,2624,2632],{},[580,2625,2626],{},[583,2627,2628,2630],{},[586,2629,588],{},[586,2631,591],{},[593,2633,2634,2645,2656,2672],{},[583,2635,2636,2639],{},[598,2637,2638],{},"The LED doesn't light up at all",[598,2640,2641,2642,2644],{},"Check PicoBricks is connected using the connect button at the top of the code area, then press ",[50,2643,2301],{}," again.",[583,2646,2647,2650],{},[598,2648,2649],{},"The brightness doesn't change when you turn the dial",[598,2651,2652,2653,2655],{},"Check your `Read Potentiometer` block is inside the `round` block, just before the ",[50,2654,2504],{},", and that the maths reads `x 255 ÷ 65535`.",[583,2657,2658,2661],{},[598,2659,2660],{},"The colour looks wrong or flickers",[598,2662,2663,2664,2666,2667,2075,2669,2671],{},"Make sure the same `Colour` variable is dropped into all three slots (",[50,2665,2565],{},", ",[50,2668,2578],{},[50,2670,2581],{},").",[583,2673,2674,2677],{},[598,2675,2676],{},"PicoBricks won't connect",[598,2678,2679,2680,2682],{},"Try a different USB cable or port, check you picked ",[50,2681,2198],{},", and press the connect button again.",{"title":674,"searchDepth":675,"depth":675,"links":2684},[],"\u002Flearn\u002Fpicobricks\u002Fdimmable-led\u002Fcover.png",[1634,2687,2378],"Raspberry Pi Pico",{},"\u002Flearn\u002Fpicobricks\u002Fdimmable-led","\u002Flearn\u002Fpicobricks\u002Fdimmable-led\u002Fdimmable-led.pdf",{"title":2388,"description":674},"learn\u002Fpicobricks\u002Fdimmable-led\u002Findex","https:\u002F\u002Fyoutu.be\u002Fu5CaiNAMwkI","to14oGJY2zhzvWMrPp7M4yYEtNdj-ZZnupyyzv1o6c4",{"id":2696,"title":2697,"body":2698,"description":674,"draft":677,"duration":2374,"extension":679,"image":3009,"kit":3010,"language":694,"level":686,"meta":3011,"navigation":688,"path":3012,"pdf":3013,"platform":1839,"seo":3014,"stem":3015,"youtube":3016,"__hash__":3017},"tutorials\u002Flearn\u002Fpicobricks\u002Ftemperature-monitoring\u002Findex.md","Temperature Monitoring",{"type":8,"value":2699,"toc":3007},[2700],[11,2701,2702,2730,2734,2739,2759,2895,2912,2935],{},[14,2703,2704,2716],{"title":16},[18,2705,2706,2707,2711,2712,119],{},"Within this PicoBricks tutorial we're going to use the ",[22,2708,2710],{"slug":2709},"temperature-sensor","temperature sensor"," to sense the temperature of the room you're in. The temperature is then outputted to the ",[22,2713,2715],{"slug":2714},"oled-screen","OLED screen",[43,2717,2718,2722],{"color":45,"icon":46},[18,2719,2720],{},[50,2721,52],{},[54,2723,2724,2727],{},[57,2725,2726],{},"How to sense the temperature of a room through code",[57,2728,2729],{},"How to output the temperature to the OLED screen",[14,2731,2732],{"title":89},[91,2733],{},[14,2735,2736],{"title":95},[97,2737],{":terms":2738},"temperature-sensor, oled-screen, forever-loop",[14,2740,2741,2754],{"title":1594},[104,2742,2743,2748,2750],{},[57,2744,1599,2745,1605],{},[113,2746,1604],{"href":1602,"rel":2747},[117],[57,2749,1608],{},[57,2751,1611,2752,1615],{},[50,2753,1614],{},[18,2755,2756],{},[141,2757],{"alt":1620,"src":2758},"\u002Flearn\u002Fpicobricks\u002Ftemperature-monitoring\u002FCodingEnvironment.webp",[14,2760,2761,2886,2892],{"title":1624},[104,2762,2763,2769,2777,2786,2813,2832,2844,2868,2878],{},[57,2764,150,2765,825,2767,1927],{},[50,2766,168],{},[175,2768,1634],{},[57,2770,150,2771,825,2773,1934,2775,182],{},[50,2772,243],{},[175,2774,888],{},[175,2776,1634],{},[57,2778,150,2779,825,2781,1944,2784,182],{},[50,2780,451],{},[175,2782,2783],{},"Clear Screen Buffer",[175,2785,888],{},[57,2787,150,2788,825,2790,1934,2793,1962,2795,2798,2799,2535,2802,2798,2805,2075,2808,327,2810,119],{},[50,2789,451],{},[175,2791,2792],{},"Write Text to Screen",[175,2794,2783],{},[50,2796,2797],{},"X"," value to ",[50,2800,2801],{},"15",[50,2803,2804],{},"Y",[50,2806,2807],{},"10",[50,2809,1634],{},[50,2811,2812],{},"Temperature:",[57,2814,150,2815,825,2817,1934,2819,1962,2822,2798,2824,331,2827,2798,2829,119],{},[50,2816,451],{},[175,2818,2792],{},[175,2820,2821],{},"Write Text to Screen X 15 Y 10 \"Temperature:\"",[50,2823,2797],{},[50,2825,2826],{},"55",[50,2828,2804],{},[50,2830,2831],{},"30",[57,2833,150,2834,825,2836,2839,2840,292,2842,119],{},[50,2835,1658],{},[175,2837,2838],{},"Read Temperature"," block and snap it onto the ",[175,2841,2792],{},[50,2843,1634],{},[57,2845,150,2846,825,2848,1934,2850,1962,2853,2798,2855,2535,2858,2798,2860,2075,2863,327,2865,119],{},[50,2847,451],{},[175,2849,2792],{},[175,2851,2852],{},"Write Text to Screen X 55 Y 30 Read Temperature",[50,2854,2797],{},[50,2856,2857],{},"35",[50,2859,2804],{},[50,2861,2862],{},"50",[50,2864,1634],{},[50,2866,2867],{},"Degrees",[57,2869,150,2870,825,2872,1934,2875,182],{},[50,2871,451],{},[175,2873,2874],{},"Show Screen Buffer",[175,2876,2877],{},"Write Text to Screen X 35 Y 50 \"Degrees\"",[57,2879,150,2880,825,2882,1934,2884,182],{},[50,2881,243],{},[175,2883,1958],{},[175,2885,2874],{},[18,2887,2888],{},[141,2889],{"alt":2890,"src":2891},"The completed block code for temperature monitoring","\u002Flearn\u002Fpicobricks\u002Ftemperature-monitoring\u002FTemperatureSensingCode.webp",[18,2893,2894],{},"We've now completed the code for our temperature monitor.",[14,2896,2897,2903,2906],{"title":2006},[104,2898,2899],{},[57,2900,811,2901,2014],{},[50,2902,2013],{},[18,2904,2905],{},"You should now see the live temperature displayed on the OLED screen. 🎉",[18,2907,2908],{},[141,2909],{"alt":2910,"src":2911},"The live room temperature shown on the OLED screen","\u002Flearn\u002Fpicobricks\u002Ftemperature-monitoring\u002FTemperatureMonitoring.gif",[14,2913,2914],{"title":549},[551,2915,2916],{},[18,2917,2918,2920,2921,2923,2924,2927,2928,2931,2932,2934],{},[50,2919,557],{}," Can you make your project react to the temperature? Try adding an ",[50,2922,85],{}," so the screen shows a message like ",[175,2925,2926],{},"Too hot!"," when the temperature climbs above a number you choose (your ",[50,2929,2930],{},"threshold","). For an extra challenge, light up an ",[50,2933,1872],{}," whenever the room gets warm.",[14,2936,2937],{"title":575},[577,2938,2939,2947],{},[580,2940,2941],{},[583,2942,2943,2945],{},[586,2944,588],{},[586,2946,591],{},[593,2948,2949,2960,2975,2994],{},[583,2950,2951,2954],{},[598,2952,2953],{},"PicoBricks won't connect, or the connect button stays greyed out",[598,2955,2956,2957,2959],{},"Check the USB cable is pushed in at both ends, click the ",[50,2958,1614],{}," button at the top of the code area, and use Google Chrome or Microsoft Edge.",[583,2961,2962,2965],{},[598,2963,2964],{},"Nothing appears on the OLED screen",[598,2966,2967,2968,2075,2970,2972,2973,644],{},"Make sure your ",[175,2969,2783],{},[175,2971,2874],{}," blocks are in place, and that all your blocks are snapped inside the ",[175,2974,888],{},[583,2976,2977,2980],{},[598,2978,2979],{},"The temperature shows once but never changes",[598,2981,652,2982,2984,2985,2987,2988,2990,2991,2993],{},[175,2983,2838],{}," block is snapped into the ",[175,2986,2792],{}," block, and that a ",[175,2989,1958],{}," block sits inside the ",[175,2992,888],{}," loop so it keeps refreshing.",[583,2995,2996,2999],{},[598,2997,2998],{},"The words overlap or sit in the wrong place",[598,3000,3001,3002,2075,3004,3006],{},"Have a look at your ",[50,3003,2797],{},[50,3005,2804],{}," values, they set where each piece of text sits on the screen.",{"title":674,"searchDepth":675,"depth":675,"links":3008},[],"\u002Flearn\u002Fpicobricks\u002Ftemperature-monitoring\u002Fcover.png",[1832,1833,1834,1835],{},"\u002Flearn\u002Fpicobricks\u002Ftemperature-monitoring","\u002Flearn\u002Fpicobricks\u002Ftemperature-monitoring\u002Ftemperature-monitoring.pdf",{"title":2697,"description":674},"learn\u002Fpicobricks\u002Ftemperature-monitoring\u002Findex","https:\u002F\u002Fyoutu.be\u002FK-ZN9wmLokk","nP_35_koZP2VZhxq5kOiR51xt-uuSvLvdZAo9zJoVQA",{"id":3019,"title":3020,"body":3021,"description":674,"draft":677,"duration":678,"extension":679,"image":3281,"kit":3282,"language":694,"level":686,"meta":3283,"navigation":688,"path":3284,"pdf":3285,"platform":1839,"seo":3286,"stem":3287,"youtube":3288,"__hash__":3289},"tutorials\u002Flearn\u002Fpicobricks\u002Fusing-the-button\u002Findex.md","Using the Button",{"type":8,"value":3022,"toc":3279},[3023],[11,3024,3025,3047,3051,3056,3076,3169,3189,3201],{},[14,3026,3027,3036],{"title":16},[18,3028,3029,3030,3032,3033,3035],{},"Within this guide we're going to use the push ",[22,3031,434],{"slug":434}," to control an ",[22,3034,1872],{"slug":1871}," by coding our PicoBricks board.",[43,3037,3038,3042],{"color":45,"icon":46},[18,3039,3040],{},[50,3041,52],{},[54,3043,3044],{},[57,3045,3046],{},"How to control an LED using a button",[14,3048,3049],{"title":89},[91,3050],{},[14,3052,3053],{"title":95},[97,3054],{":terms":3055},"button, led, forever-loop, if-statement",[14,3057,3058,3071],{"title":1594},[104,3059,3060,3065,3067],{},[57,3061,1599,3062,1605],{},[113,3063,1604],{"href":1602,"rel":3064},[117],[57,3066,1608],{},[57,3068,1611,3069,1615],{},[50,3070,1614],{},[18,3072,3073],{},[141,3074],{"alt":1620,"src":3075},"\u002Flearn\u002Fpicobricks\u002Fusing-the-button\u002FCodingEnvironment.webp",[14,3077,3078,3160,3166],{"title":1624},[104,3079,3080,3088,3096,3106,3114,3126,3140,3148],{},[57,3081,150,3082,3084,3085,3087],{},[50,3083,168],{},". Select and drag a ",[175,3086,1634],{}," block to the code area and drop it.",[57,3089,150,3090,825,3092,1934,3094,182],{},[50,3091,243],{},[175,3093,888],{},[175,3095,1634],{},[57,3097,150,3098,3100,3101,3103,3104,182],{},[50,3099,272],{},". Select an ",[175,3102,1673],{}," block and snap it inside the ",[175,3105,888],{},[57,3107,150,3108,3100,3110,2839,3112,182],{},[50,3109,272],{},[175,3111,326],{},[175,3113,291],{},[57,3115,150,3116,825,3118,3121,3122,1702,3124,2516],{},[50,3117,1658],{},[175,3119,3120],{},"Read Button"," block and snap it within the first blank space of the ",[175,3123,291],{},[50,3125,326],{},[57,3127,150,3128,825,3130,3132,3133,3135,3136,327,3138,119],{},[50,3129,1709],{},[175,3131,334],{}," block and snap it in the blank space after the ",[50,3134,326],{}," sign. Change the ",[50,3137,334],{},[50,3139,337],{},[57,3141,150,3142,825,3144,1944,3146,182],{},[50,3143,1658],{},[175,3145,1961],{},[175,3147,291],{},[57,3149,150,3150,825,3152,1944,3154,1962,3156,327,3158,119],{},[50,3151,1658],{},[175,3153,1961],{},[175,3155,1739],{},[50,3157,1950],{},[50,3159,1981],{},[18,3161,3162],{},[141,3163],{"alt":3164,"src":3165},"The completed block code for the button-controlled LED","\u002Flearn\u002Fpicobricks\u002Fusing-the-button\u002FCompletedButtonCode.webp",[18,3167,3168],{},"We've now completed the code for our button-controlled LED.",[14,3170,3171,3180,3183],{"title":2006},[104,3172,3173,3177],{},[57,3174,811,3175,2014],{},[50,3176,2013],{},[57,3178,3179],{},"Press the button on your PicoBricks board.",[18,3181,3182],{},"When the button is pressed you should see the LED turn on, and switch off again when you let go. 🎉",[18,3184,3185],{},[141,3186],{"alt":3187,"src":3188},"The LED turning on while the button is pressed","\u002Flearn\u002Fpicobricks\u002Fusing-the-button\u002FUsingTheButtonDemo.gif",[14,3190,3191],{"title":549},[551,3192,3193],{},[18,3194,3195,3197,3198,3200],{},[50,3196,557],{}," Now you can switch a light on with a button, what else could you control? Try swapping a ",[175,3199,1943],{}," block for a different brick, like making the buzzer beep while the button is held down. Can you get two things to happen from one press?",[14,3202,3203],{"title":575},[577,3204,3205,3213],{},[580,3206,3207],{},[583,3208,3209,3211],{},[586,3210,588],{},[586,3212,591],{},[593,3214,3215,3229,3245,3267],{},[583,3216,3217,3220],{},[598,3218,3219],{},"The LED doesn't come on when I press the button",[598,3221,3222,3223,2984,3225,1702,3227,2516],{},"Check the USB cable is pushed in at both ends and that the Brick IDE shows it's connected to your PicoBricks board. Then check the ",[175,3224,3120],{},[175,3226,291],{},[175,3228,326],{},[583,3230,3231,3234],{},[598,3232,3233],{},"The LED stays on all the time",[598,3235,3236,3237,2075,3239,3241,3242,3244],{},"Look at your ",[175,3238,291],{},[175,3240,1739],{}," blocks and make sure the right ",[175,3243,1943],{}," block sits inside each one, so the light knows when to switch on and when to switch off.",[583,3246,3247,3249],{},[598,3248,2069],{},[598,3250,3251,3252,3254,3255,3257,3258,2666,3260,2075,3262,3264,3265,119],{},"Drop each block just inside the one above it. The ",[175,3253,1673],{}," block needs to sit inside the ",[175,3256,888],{}," loop, and the ",[175,3259,3120],{},[175,3261,326],{},[175,3263,334],{}," blocks all tuck into the top of the ",[175,3266,291],{},[583,3268,3269,3271],{},[598,3270,2105],{},[598,3272,3273,3274,3276,3277,2111],{},"Reconnect the board using the ",[50,3275,1614],{}," button at the top of the code area, then press ",[50,3278,2013],{},{"title":674,"searchDepth":675,"depth":675,"links":3280},[],"\u002Flearn\u002Fpicobricks\u002Fusing-the-button\u002Fcover.png",[1832,1833,1834,1835],{},"\u002Flearn\u002Fpicobricks\u002Fusing-the-button","\u002Flearn\u002Fpicobricks\u002Fusing-the-button\u002Fusing-the-button.pdf",{"title":3020,"description":674},"learn\u002Fpicobricks\u002Fusing-the-button\u002Findex","https:\u002F\u002Fyoutu.be\u002FHGowhuRMlRM","MApG1ETjhw88wwKf926ynKFGkMPsPvNqLH-ETMn-fOM",1785347038220]