Skip to content

Instantly share code, notes, and snippets.

@geerlingguy
Last active June 20, 2025 18:49
Show Gist options
  • Save geerlingguy/4d519887aeb462ba9501961a32ae3f71 to your computer and use it in GitHub Desktop.
Save geerlingguy/4d519887aeb462ba9501961a32ae3f71 to your computer and use it in GitHub Desktop.
PicoBricks Demo Code from Jeff Geerling's Jun 2025 Microcontroller video

PicoBricks Microcontroller Demos

These .pb (PicoBricks) IDE files are meant to be used with a PicoBricks board. I demonstrate how they all work (and how I built them) in this YouTube video:

https://www.youtube.com/watch?v=Sd42q3OaOrE

How to use these files

These files are meant to be opened in the PicoBricks BricksIDE, available on http://ide.picobricks.com

Save one of these .pb files to your computer. Then in the BricksIDE editor, choose File > Open Project, and then choose the .pb file.

Make sure you're connected to the PicoBricks board, and then click 'Run' to run the program.

<xml xmlns="https://developers.google.com/blockly/xml"><block type="Robotistan_Start" id="E+:#PXz(d[xy9Ftw(2;a" x="410" y="70"><next><block type="control_forever" id="pkoglQ)$LhkPwPFOURvB"><statement name="DO"><block type="clearScreen" id="T}GLYUn#)5uH/R|K=K*L"><next><block type="writeTextScreen" id="}mIkm!$)5cGd=;=k=t)`"><value name="XPos"><shadow type="math_positive_number" id=".#xV[it_d/2F{)`Bngu:"><field name="NUM">18</field></shadow></value><value name="YPos"><shadow type="math_positive_number" id="br.}uC$S703JTsF0,nt7"><field name="NUM">30</field></shadow></value><value name="WriteValue"><shadow type="text" id="2[YX5{avsrpKRHsf9wZP"><field name="TEXT">Hello world!</field></shadow></value><next><block type="showScreen" id="}Pkr^rco(N455-t@-4+N"><next><block type="control_repeat" id="=D8@EXvg$]H,mjtT8Tuc"><value name="TIMES"><shadow type="math_number" id="a$*sT^+v83bFp(a~wz!h"><field name="NUM">10</field></shadow></value><statement name="DO"><block type="setLedValue" id="gMhYL|Fp=Nr)x0n~)eYo"><field name="VALUE">1</field><next><block type="control_wait" id="wmNS}$VS55wD;{em}!{/"><value name="DURATION"><shadow type="math_number" id="/xalSB5.v=c@i1-NG~{l"><field name="NUM">1</field></shadow></value><next><block type="setLedValue" id="UjkuH+]KOifoZkK1#/Ak"><field name="VALUE">0</field><next><block type="control_wait" id="K6CVaW(:[email protected]!B"><value name="DURATION"><shadow type="math_number" id="G{5X8]AXH^(h8Dp2F]_M"><field name="NUM">1</field></shadow></value></block></next></block></next></block></next></block></statement></block></next></block></next></block></next></block></statement></block></next></block></xml>
<xml xmlns="https://developers.google.com/blockly/xml"><block type="Robotistan_Start" id="lN%3dIj;?1G:@Y5Z!v5#" x="430" y="50"><next><block type="control_forever" id="9%8wdK$}i)%(DNeB#gxp"><statement name="DO"><block type="print" id="Rwu)(sgj@i-RC^qkf@B:"><value name="WriteValue"><shadow type="text" id="Jb?|6~ODcA43$xV7t$Nz"><field name="TEXT"/></shadow><block type="readLightSersor" id="Pw0Kt6Jx94^j}z0d.Al9"/></value><next><block type="controls_if" id="2(hu+}Z^vjaW|%seR`+="><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation><value name="IF0"><block type="logic_compare" id="X=_H49?}/Oi0}Bamr4Cf"><field name="OP">GT</field><value name="A"><block type="readLightSersor" id="fy%KiCbSKAM97U{:`qVm"/></value><value name="B"><block type="math_number" id="/cELddCmXne%N!jaqiBc"><field name="NUM">2000</field></block></value></block></value><statement name="DO0"><block type="neoPixelColour" id="|g4C~t15QS;EyA3i8$`O"><value name="ColourValue"><shadow xmlns="http://www.w3.org/1999/xhtml" type="colour_picker"><field name="COLOUR">#ffffff</field></shadow><block type="colour_picker" id="[dDB1`T,KOkaYFyJUPfR"><field name="COLOUR">#ffffff</field></block></value></block></statement><statement name="ELSE"><block type="neoPixelColour" id="EqU.DTyvNGQdqsv@^qZe"><value name="ColourValue"><shadow xmlns="http://www.w3.org/1999/xhtml" type="colour_picker"><field name="COLOUR">#ffffff</field></shadow><block type="colour_picker" id="mN`Oe|j8c`Q?@W~fG?a3"><field name="COLOUR">#000000</field></block></value></block></statement><next><block type="control_wait" id="~[JxjRk{9)0ps[M9iQHX"><value name="DURATION"><shadow type="math_number" id="$=-@ISwzVAna~0%e-+8%"><field name="NUM">0.1</field></shadow></value></block></next></block></next></block></statement></block></next></block></xml>
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="w[nv8|(yI4`8t)K/^p4h">light_percentage</variable></variables><block type="procedures_defnoreturn" id="|Sj}mVe4fl$Xw3rmtkeX" x="950" y="50"><field name="NAME">get_light_percentage</field><statement name="STACK"><block type="print" id="re,[|5I2aFM@ZCPMx(5:"><value name="WriteValue"><shadow type="text"><field name="TEXT">PicoBricks</field></shadow><block type="readLightSersor" id="d`k*[*Cg6Y`KP-e$T@2f"/></value><next><block type="variables_set" id="q-mB2~13(sb{AFt6?[nN"><field name="VAR" id="w[nv8|(yI4`8t)K/^p4h">light_percentage</field><value name="VALUE"><block type="math_round" id="~*9iV#=fG.I1)J{}o]Sf"><field name="OP">ROUND</field><value name="NUM"><shadow type="math_number" id=".WxoEyweT^9+SwhP8?GA"><field name="NUM">3.1</field></shadow><block type="math_arithmetic" id="}UhA2$/SBIj1{xgeaC,T"><field name="OP">MULTIPLY</field><value name="A"><shadow type="math_number" id="W?_8uBx6u$jJ+_:Byw^*"><field name="NUM">1</field></shadow><block type="math_arithmetic" id="?u6+Gzk2EqDm+Bb=SeEv"><field name="OP">DIVIDE</field><value name="A"><shadow type="math_number" id="Jm|H`-s~p[H)])PKW}i."><field name="NUM">1</field></shadow><block type="readLightSersor" id="2JuP,V{pkkSCdV!Vq99B"/></value><value name="B"><shadow type="math_number" id="4.BOhd^#%z)xs%Pwc@;@"><field name="NUM">14000</field></shadow></value></block></value><value name="B"><shadow type="math_number" id="sj4+Q.%QA9zJsxD*vWHP"><field name="NUM">100</field></shadow></value></block></value></block></value><next><block type="print" id="j|t3S~%{]7zx%d?n1[zJ"><value name="WriteValue"><shadow type="text" id="daB8MN6,Nkj5/nH}kG]N"><field name="TEXT">PicoBricks</field></shadow><block type="variables_get" id="4ZaCooTyJ14~c*!xiw}#"><field name="VAR" id="w[nv8|(yI4`8t)K/^p4h">light_percentage</field></block></value></block></next></block></next></block></statement></block><block type="Robotistan_Start" id=".UWLZ;6DG_:nYc~g@W!$" x="438" y="87"><next><block type="control_forever" id="(+*jP(3K)uHv|vZkp/CH"><statement name="DO"><block type="clearScreen" id="XD^o_h@`=~87p$=Jo+tn"><next><block type="procedures_callnoreturn" id=")s0y)6fcxlo/6rbpRRvo"><mutation name="get_light_percentage"/><next><block type="writeTextScreen" id="hh?lKI4qZzillB9ylNJC"><value name="XPos"><shadow type="math_positive_number" id="jX4OFd;F,*8()?f8RM5T"><field name="NUM">5</field></shadow></value><value name="YPos"><shadow type="math_positive_number" id="$un!Q~r=Ttis|zU`sF]7"><field name="NUM">5</field></shadow></value><value name="WriteValue"><shadow type="text" id="Qh92m_?nhHw$?w/rO_lC"><field name="TEXT">Light Level</field></shadow></value><next><block type="writeTextScreen" id="$KJnqp9F8GVr_FTFFh?M"><value name="XPos"><shadow type="math_positive_number" id="x2Mm(uJJGvm6uTC9N0C-"><field name="NUM">5</field></shadow></value><value name="YPos"><shadow type="math_positive_number" id="Q@][email protected]]yM(c35Tty,"><field name="NUM">15</field></shadow></value><value name="WriteValue"><shadow type="text" id="Zsric8[T^WQIz-!O3RmZ"><field name="TEXT">PicoBricks</field></shadow><block type="list_combined" id="|yPav*`:rCRl2kiJy[Sw"><value name="STR1"><shadow type="text" id="^ijk~r$ub!3I^X[LH@|)"><field name="TEXT">Pico</field></shadow><block type="variables_get" id="y9}9SG/a#s?X+?:pVTC%"><field name="VAR" id="w[nv8|(yI4`8t)K/^p4h">light_percentage</field></block></value><value name="STR2"><shadow type="text" id="gov*uXBSq4,U9lr5hHpz"><field name="TEXT">% darkness</field></shadow></value></block></value><next><block type="showScreen" id="dF#kn;.V;][E4y,{St$D"><next><block type="controls_if" id="[eIO:PysfjY]%tC-,tSv"><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation><value name="IF0"><block type="logic_compare" id="?oS/dRk;D$$`4,!}!AIZ"><field name="OP">GT</field><value name="A"><block type="variables_get" id="5ql3;q_f^:Rb[9egs-|e"><field name="VAR" id="w[nv8|(yI4`8t)K/^p4h">light_percentage</field></block></value><value name="B"><block type="math_number" id="-mVK~re_|a8bY|748$yh"><field name="NUM">30</field></block></value></block></value><statement name="DO0"><block type="neoPixelColour" id="@2e!U;T,WR$4X_s*T#AO"><value name="ColourValue"><shadow xmlns="http://www.w3.org/1999/xhtml" type="colour_picker"><field name="COLOUR">#ffffff</field></shadow><block type="colour_picker" id=":jPavO)]#L8@zMqqHuY,"><field name="COLOUR">#cccccc</field></block></value></block></statement><statement name="ELSE"><block type="neoPixelClear" id=":[lsE3v;bR1:{@czw|9V"><next><block type="setLedValue" id="btUd()N8jC`X(/0G.V)|"><field name="VALUE">1</field></block></next></block></statement><next><block type="control_wait" id="T%*{QAxO#sWiqUj^STaO"><value name="DURATION"><shadow type="math_number" id="=rC(3)]*t4l?^ZnEDW/="><field name="NUM">0.1</field></shadow></value></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></next></block></xml>
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="w[nv8|(yI4`8t)K/^p4h">light_percentage</variable><variable id="[+jMUTz[~VxgMEYU,At.">color_level</variable><variable id="MuC[otIWlVBWMoF$3Cme">armed</variable></variables><block type="Robotistan_Start" id="QZJqx8QQ%pH3k9nJj3H4" x="-230" y="-90"><next><block type="while_loop" id="2KQ?7@t}SPJT[UWnhC@-"><value name="WHILE"><block type="logic_compare" id="gzd,9}uM?CA}`,qao%2I"><field name="OP">EQ</field><value name="A"><block type="readButton" id="OWgg1%6Y:Yuj~sQUA2d-"/></value><value name="B"><block type="math_number" id="%!JQhZAL`6F$ULTW2wsz"><field name="NUM">0</field></block></value></block></value><statement name="DO"><block type="procedures_callnoreturn" id="uZ$2]-l%O64MgO=24^;t"><mutation name="arm_message"/></block></statement><next><block type="control_wait" id="qj$;1C@z=jd4I4uSuv@H"><value name="DURATION"><shadow type="math_number" id="$wg+R|W)^KUL(0;Ul@V#"><field name="NUM">0.1</field></shadow></value><next><block type="control_forever" id="UG?+@azU`yB+8A-)!Ct|"><statement name="DO"><block type="while_loop" id="A2OQnCz[*X$Ck,]`Yi3e"><value name="WHILE"><block type="variables_get" id="w}H^A|4Qe%J$7)yVk5AI"><field name="VAR" id="MuC[otIWlVBWMoF$3Cme">armed</field></block></value><statement name="DO"><block type="clearScreen" id="j-n/TC3S(Z6m2Ud%IHpr"><next><block type="writeTextScreen" id="sFHiI=#sB{1A4%gmgL7."><value name="XPos"><shadow type="math_positive_number" id="mo$?(=[4%(B-.f#vs#~I"><field name="NUM">28</field></shadow></value><value name="YPos"><shadow type="math_positive_number" id="F|ldD{#~;2k._:{i|==F"><field name="NUM">10</field></shadow></value><value name="WriteValue"><shadow type="text" id="?q5f5mXLQ4l*4/QB6en`"><field name="TEXT">Pop a Cap</field></shadow></value><next><block type="writeTextScreen" id="4{JXsUFt;_MZM:NKf[of"><value name="XPos"><shadow type="math_positive_number" id="C1j$pu_?@jMqQkSiZ?(["><field name="NUM">40</field></shadow></value><value name="YPos"><shadow type="math_positive_number" id="yiZw-l*Ur/F0RK2Serc7"><field name="NUM">40</field></shadow></value><value name="WriteValue"><shadow type="text" id="KmwZBh++K8%V^w16stEG"><field name="TEXT">ARMED</field></shadow></value><next><block type="showScreen" id=")(ey!]MaJ]O(*y=QPW+-"><next><block type="setLedValue" id="HdQ~iX8D/f1+P~#?e:KR"><field name="VALUE">1</field><next><block type="neoPixelColour" id="C%pSU/D!R~k/u}+p5}^~"><value name="ColourValue"><shadow xmlns="http://www.w3.org/1999/xhtml" type="colour_picker"><field name="COLOUR">#ffffff</field></shadow><block type="colour_picker" id="s$M6t:#C%f+V0Vk~,oBv"><field name="COLOUR">#330000</field></block></value><next><block type="control_wait" id="Ga7cgG[u/,1F(=EutXq0"><value name="DURATION"><shadow type="math_number" id="f;[email protected]%WNCb:"><field name="NUM">0.1</field></shadow></value><next><block type="onIRReceiving" id="cFxIf^eB*%!%i%QRvILj"><statement name="DO"><block type="controls_if" id="k1E,q7IKosHktz1Q:t1T"><value name="IF0"><block type="isButtonPressed" id="kQe:]::1;9]L8ui#TpP/"><field name="VALUE">IR_RX.number_star</field></block></value><statement name="DO0"><block type="procedures_callnoreturn" id="w~j#-FPt?S?ItrVn|y6C"><mutation name="pop_cap"/></block></statement></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement><next><block type="procedures_callnoreturn" id="i!0C:*gm=2Ah=!HeqQZy"><mutation name="arm_message"/></block></next></block></statement></block></next></block></next></block></next></block><block type="procedures_defnoreturn" id="@%jj:H#eD,#_:/1Iv/M." x="350" y="-90"><field name="NAME">arm_message</field><statement name="STACK"><block type="clearScreen" id="niKnsdx1:.YG#n!]!g#="><next><block type="writeTextScreen" id="JO@)HDTyg+_EJE]VclL]"><value name="XPos"><shadow type="math_positive_number" id="A5!9CRJHYC69c.l4U/}^"><field name="NUM">28</field></shadow></value><value name="YPos"><shadow type="math_positive_number" id="ic+awq4]AHfDKQ91l*w1"><field name="NUM">10</field></shadow></value><value name="WriteValue"><shadow type="text" id="(Tgs`v]av,1xBESkQg6;"><field name="TEXT">Pop a Cap</field></shadow></value><next><block type="writeTextScreen" id=",1~!BNCWL1G$}W^S/uC@"><value name="XPos"><shadow type="math_positive_number" id="Xv.Cd$]ytv=*2O:@`gX}"><field name="NUM">20</field></shadow></value><value name="YPos"><shadow type="math_positive_number" id="Uza75gi8T@s%-dMdklX2"><field name="NUM">35</field></shadow></value><value name="WriteValue"><shadow type="text" id="N@!$93oemyLVYUXS$Zas"><field name="TEXT">Push Button</field></shadow></value><next><block type="writeTextScreen" id="]+=@W=!}o;j;atx^R[%l"><value name="XPos"><shadow type="math_positive_number" id="cIpoC4R}iJ,~st4IP8ej"><field name="NUM">40</field></shadow></value><value name="YPos"><shadow type="math_positive_number" id="tAtY$9XXl2ZxA$@TO_mJ"><field name="NUM">45</field></shadow></value><value name="WriteValue"><shadow type="text" id="RIYy~nk!EZ4:`%WOJ]@="><field name="TEXT">to Arm</field></shadow></value><next><block type="showScreen" id="[email protected]?i@^%;=j3~"><next><block type="neoPixelColour" id="I(j];C?Y8nnvKQq^t/#@"><value name="ColourValue"><shadow xmlns="http://www.w3.org/1999/xhtml" type="colour_picker"><field name="COLOUR">#ffffff</field></shadow><block type="colour_picker" id="3-gvrM9b!#p|Gw$~noTo"><field name="COLOUR">#000000</field></block></value><next><block type="setLedValue" id="MTU)sp:I$-,7RwxVU*;k"><field name="VALUE">0</field><next><block type="controls_if" id="x|,d{Y;g(I5RI8]z[~hX"><value name="IF0"><block type="readButton" id="!%R^$Ex)=DYm|JpZ5{(T"/></value><statement name="DO0"><block type="variables_set" id="OpD-z^+kG;!|YCv#oD/R"><field name="VAR" id="MuC[otIWlVBWMoF$3Cme">armed</field><value name="VALUE"><block type="math_number" id="wczAVS}{`d]YSoz@URKr"><field name="NUM">1</field></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block><block type="procedures_defnoreturn" id="H6jX$JQGRzB5O[|jz~!h" x="350" y="490"><field name="NAME">pop_cap</field><statement name="STACK"><block type="print" id="+.UGDI28?cBmKV_drw[i"><value name="WriteValue"><shadow type="text" id="P9FhF$CR!Cx](|Bcr=/["><field name="TEXT">POPPING CAP NOW</field></shadow></value><next><block type="setLedValue" id="QrABqJm5+gcnQ_]}`t(!"><field name="VALUE">0</field><next><block type="neoPixelColour" id="$!w:025LnYbxieGrtJ${"><value name="ColourValue"><shadow xmlns="http://www.w3.org/1999/xhtml" type="colour_picker"><field name="COLOUR">#ffffff</field></shadow><block type="colour_picker" id="kS9QmS.%6_wnZI.G~bmC"><field name="COLOUR">#ff0000</field></block></value><next><block type="clearScreen" id="MTVk1!7%i=VRb)vv3.U@"><next><block type="writeTextScreen" id="_GKt!f4eo{O:psOH;wOZ"><value name="XPos"><shadow type="math_positive_number" id="a3o`46^!9,,t7Vn)iN+["><field name="NUM">28</field></shadow></value><value name="YPos"><shadow type="math_positive_number" id="mN]TkJ]mT:Ef;`vKa1TS"><field name="NUM">10</field></shadow></value><value name="WriteValue"><shadow type="text" id="Tgdv,!oYhDI|5:9gJA9y"><field name="TEXT">Pop a Cap</field></shadow></value><next><block type="writeTextScreen" id="x7.*c*s9Va=9l`$bq!a{"><value name="XPos"><shadow type="math_positive_number" id="1y6u?f~1Bx*Cjn2fpU5C"><field name="NUM">42</field></shadow></value><value name="YPos"><shadow type="math_positive_number" id="QK51h!pX[OvApt=|q*[|"><field name="NUM">40</field></shadow></value><value name="WriteValue"><shadow type="text" id="[YcM06uX[vxHWQ6USU*Y"><field name="TEXT">BOOM!</field></shadow></value><next><block type="showScreen" id="k2J`@]jn!ZG(I3VBTBB*"><next><block type="setRelayValue" id="@9^CD!#G%PyOM?(Fo(wf"><field name="VALUE">1</field><next><block type="control_wait" id="(UfwEif7@k^mzFB2(}kF"><value name="DURATION"><shadow type="math_number" id=".ed.^x.)Xl%UMud2`*)n"><field name="NUM">3</field></shadow></value><next><block type="setRelayValue" id=")e{y]M#zR|wcDhKp0:q@"><field name="VALUE">0</field><next><block type="variables_set" id="%Nb[I03{au1y~VM6t4[n"><field name="VAR" id="MuC[otIWlVBWMoF$3Cme">armed</field><value name="VALUE"><block type="math_number" id="E4~XKNW9n9a`lwctCZTD"><field name="NUM">0</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment