[{"data":1,"prerenderedAt":691},["ShallowReactive",2],{"lessons":3},[4,113,360],{"id":5,"title":6,"body":7,"chapterName":99,"chapterNumber":100,"description":101,"extension":102,"includesCode":103,"lessonNumber":100,"meta":104,"navigation":105,"path":106,"seo":107,"starterCode":108,"stem":109,"tags":110,"__hash__":112},"lessons/lessons/1-01-intro-circuits.md","Introduction to Circuits",{"type":8,"value":9,"toc":90},"minimark",[10,15,19,23,26,32,36,54,58,62,66,69,73,76,80,84,87],[11,12,14],"h2",{"id":13},"introduction","Introduction",[16,17,18],"p",{},"In this lesson, we'll cover the basics of circuits and electricity, and how to design your very first circuit using the components in your kit.",[11,20,22],{"id":21},"the-controller","The Controller",[16,24,25],{},"Projects here use our special controller, which you are able to control with your code from the web. You'll see five\npins on the top that you can plug wires into. On the left, labeled '5V' is the positive power supply, and on the right,\nlabeled 'GND' is the ground. The three pins in the middle are your controllable pins, called GPIO (General Purpose\nInput/Output) pins. You can use these to send signals to components like LEDs, or read signals from sensors.",[27,28],"img",{"alt":29,"src":30,"width":31},"Controller Layout","/images/lessons/01-controller-guide.svg","40%",[11,33,35],{"id":34},"electronic-signals","Electronic Signals",[16,37,38,39,43,44,47,48,50,51,53],{},"There are two types of electronic signals, analog and digital. An analog signal can take on any value within a range,\nwhile a digital signal can only be one of two values: ",[40,41,42],"code",{},"HIGH"," (on) or ",[40,45,46],{},"LOW"," (off). With an analog pin, we can set the\nvalue\nto anything between 0 and 255, which corresponds to a voltage between 0V and 5V. With a digital pin, we can only set it\nto\n",[40,49,42],{}," (5V) or ",[40,52,46],{}," (0V).",[27,55],{"alt":56,"src":57,"width":31},"Analog Signal diagram","/images/lessons/01-analog-signal.svg",[27,59],{"alt":60,"src":61,"width":31},"Digital Signal diagram","/images/lessons/01-digital-signal.svg",[11,63,65],{"id":64},"circuits","Circuits",[16,67,68],{},"In an electric circuit, current flows from the positive power supply (5V) through the components and back to ground (\nGND). For a component to work, it needs to be part of a complete circuit. This means that it must be connected in such a\nway that current can flow through it from some sort of power supply to ground. If there is a break in the circuit, the\ncurrent cannot flow and the component will not work.",[27,70],{"alt":71,"src":72,"width":31},"Example basic circuit with an LED and resistor in series","/images/lessons/01-basic-circuit.svg",[16,74,75],{},"Electricity has three main properties: voltage, current, and resistance. Voltage is the potential difference between two\npoints in a circuit, current is the flow of electric charge, and resistance is the opposition to current flow. Ohm's Law\ndescribes the relationship between these properties: V = I * R, where V is voltage, I is current, and R is resistance.",[27,77],{"alt":78,"src":79,"width":31},"Cartoon graphic demonstrating Ohm's law with people pushing through a tube","/images/lessons/01-ohms-law.svg",[11,81,83],{"id":82},"circuits-with-the-kit","Circuits with the Kit",[16,85,86],{},"In the next lessons, we'll be building circuits using the components in your kit. You'll learn how to connect them to\nthe controller and write code to control them.",[16,88,89],{},"Consider when power will flow through the circuits you build. For example, if you connect an LED directly to the 5V pin\nand GND, it will light up as soon as you connect it. If you want to control it with code, you need to connect it to one\nof the GPIO pins instead, so that you can turn it on and off with your code. Also, remember that components like LEDs\nrequire a resistor to limit the current and prevent damage. Always check the specifications of your components and use\nthe appropriate resistors when building your circuits.",{"title":91,"searchDepth":92,"depth":92,"links":93},"",2,[94,95,96,97,98],{"id":13,"depth":92,"text":14},{"id":21,"depth":92,"text":22},{"id":34,"depth":92,"text":35},{"id":64,"depth":92,"text":65},{"id":82,"depth":92,"text":83},"Getting Started",1,"Understand how circuits and electricity work, and how you can design your very first circuit.","md",false,{},true,"/lessons/1-01-intro-circuits",{"title":6,"description":101},null,"lessons/1-01-intro-circuits",[111,64],"beginner","meO1BX28HUW92VTK9D7p_W20PpeWI1jDKeP6DBBnWJ0",{"id":114,"title":115,"body":116,"chapterName":350,"chapterNumber":92,"description":351,"extension":102,"includesCode":105,"lessonNumber":100,"meta":352,"navigation":105,"path":353,"seo":354,"starterCode":355,"stem":356,"tags":357,"__hash__":359},"lessons/lessons/2-01-blinky.md","Blinky",{"type":8,"value":117,"toc":342},[118,120,123,127,130,133,136,139,143,146,209,213,216,262,338],[11,119,14],{"id":13},[16,121,122],{},"In this lesson, we'll cover the basics of circuits and electricity, and how to design your very first circuit using the\ncomponents in your kit. The goal of this project is to create a simple circuit with an LED that blinks on and off at a\nregular interval.",[11,124,126],{"id":125},"wiring-the-circuit","Wiring the Circuit",[16,128,129],{},"To build the Blinky circuit, you'll need to connect an LED and a resistor to one of the GPIO pins on your controller.\nRemember that the LED is directional, meaning it will only light up if you connect it the right way. There is a small\narrow next to the LED symbol on the components in your kit that indicates the direction of current flow. Make sure that\nthe arrow correctly points from higher voltage towards ground. The resistor should be connected in series with the LED\nto limit the current and prevent it from burning out. You can connect the resistor either before or after the LED in the\ncircuit.",[16,131,132],{},"If you'd like, you can test this circuit by using the 5V pin instead of a GPIO pin. If you connect the LED and resistor\nin series between the 5V pin and GND, the LED should light up as soon as you connect it. This can be a good way to\nverify that your circuit is wired correctly before you start writing code to control it.",[16,134,135],{},"We have included below the diagram from lesson 1-01 Circuits, which shows a basic circuit with an LED and resistor in\nseries. You can use this as a reference for how to wire your Blinky circuit. Remember here that our source of positive\nvoltage is going to be one of the GPIO pins instead of the 5V pin, but the rest of the circuit will look the same.",[27,137],{"alt":71,"src":72,"width":138},"80%",[11,140,142],{"id":141},"writing-the-code","Writing the Code",[16,144,145],{},"We've left comments for you in the starter code to guide you through writing the code to control your Blinky circuit. As\na refresher, here are some of the functions you may wish to use.",[147,148,149,172],"table",{},[150,151,152],"thead",{},[153,154,155,162,167],"tr",{},[156,157,158],"th",{},[159,160,161],"strong",{},"Function",[156,163,164],{},[159,165,166],{},"Description",[156,168,169],{},[159,170,171],{},"Usage",[173,174,175,187,198],"tbody",{},[153,176,177,181,184],{},[178,179,180],"td",{},"digitalWrite",[178,182,183],{},"Instructs a pin to output a digital signal until changed.",[178,185,186],{},"digitalWrite(#, HIGH/LOW);",[153,188,189,192,195],{},[178,190,191],{},"pinMode",[178,193,194],{},"Sets a pin to either be an ouptut or an input from here on out.",[178,196,197],{},"pinMode(#, OUTPUT/INPUT);",[153,199,200,203,206],{},[178,201,202],{},"delay",[178,204,205],{},"Waits without doing anything for a specified length of time, in milliseconds. (1000 milliseconds = 1 second)",[178,207,208],{},"delay(1000);",[11,210,212],{"id":211},"testing-your-circuit","Testing Your Circuit",[16,214,215],{},"Once you have your circuit wired and your code written, you can test it out by running your program. If everything is\nset up correctly, you should see your LED blink on and off at a regular interval. If it's not working, double-check your\nwiring and make sure your code is correct. If you need, you can read through the solution below.",[217,218,219,223,243,247],"hint-section",{},[11,220,222],{"id":221},"code-hints","Code Hints",[224,225,226,230,240],"ul",{},[227,228,229],"li",{},"In setup, your only goal should be to set your chosen pin's mode. Output mode lets you turn the pin on and off with\ncode, while input mode lets you wanted to read a value from that pin, such as from a sensor. Which do you think you\nneed for this project?",[227,231,232,233,236,237,239],{},"Remember that ",[40,234,235],{},"delay()"," takes milliseconds, where 1 second is equal to 1000 milliseconds. If you want your LED to stay\non for 1 second and then off for 1 second, how many milliseconds should you pass to ",[40,238,235],{},"?",[227,241,242],{},"digitalWrite(pin, HIGH/LOW) is the command that turns your specified pin on or off. Which do you think you need to\nturn the LED on? Which do you need to turn it off?",[11,244,246],{"id":245},"circuit-hints","Circuit Hints",[224,248,249,256,259],{},[227,250,251,252,255],{},"Remember that a circuit needs to a few things: it must be a ",[159,253,254],{},"closed loop"," that flows from a power source, eventually\nto ground. To get the LED to light up, it will need to be a part of that circuit.",[227,257,258],{},"You will need your circuit to flow from the positive voltage, in this case, one of the numbered GPIO pins, through the\nLED and resistor, and back to ground (GND).",[227,260,261],{},"Make sure your LED is connected in the right direction. The arrow on the LED symbol on the components in your kit\nindicates the direction of current flow. The arrow should point from higher voltage towards ground.",[263,264,265,268,334],"solution-section",{},[16,266,267],{},"Below is the code for the project, and a full diagram of the wiring.",[269,270,274],"pre",{"className":271,"code":272,"language":273,"meta":91,"style":91},"language-cpp shiki shiki-themes github-light github-dark","void setup() {\n  pinMode(3, OUTPUT);\n}\n\nvoid loop() {\n  digitalWrite(3, HIGH);\n  delay(1000);\n  digitalWrite(3, LOW);\n  delay(1000);\n}\n","cpp",[40,275,276,283,288,294,300,306,312,318,324,329],{"__ignoreMap":91},[277,278,280],"span",{"class":279,"line":100},"line",[277,281,282],{},"void setup() {\n",[277,284,285],{"class":279,"line":92},[277,286,287],{},"  pinMode(3, OUTPUT);\n",[277,289,291],{"class":279,"line":290},3,[277,292,293],{},"}\n",[277,295,297],{"class":279,"line":296},4,[277,298,299],{"emptyLinePlaceholder":105},"\n",[277,301,303],{"class":279,"line":302},5,[277,304,305],{},"void loop() {\n",[277,307,309],{"class":279,"line":308},6,[277,310,311],{},"  digitalWrite(3, HIGH);\n",[277,313,315],{"class":279,"line":314},7,[277,316,317],{},"  delay(1000);\n",[277,319,321],{"class":279,"line":320},8,[277,322,323],{},"  digitalWrite(3, LOW);\n",[277,325,327],{"class":279,"line":326},9,[277,328,317],{},[277,330,332],{"class":279,"line":331},10,[277,333,293],{},[27,335],{"alt":336,"src":337},"Solution wiring to blinky circuit","/images/lessons/02-01-blinky-solution.svg",[339,340,341],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":91,"searchDepth":92,"depth":92,"links":343},[344,345,346,347,348,349],{"id":13,"depth":92,"text":14},{"id":125,"depth":92,"text":126},{"id":141,"depth":92,"text":142},{"id":211,"depth":92,"text":212},{"id":221,"depth":92,"text":222},{"id":245,"depth":92,"text":246},"First Projects","Blink an LED on and off using your controller and code. This is the classic first project for learning how to control circuits with code.",{},"/lessons/2-01-blinky",{"title":115,"description":351},"2-01-blinky.cpp","lessons/2-01-blinky",[111,64,40,358],"led","O42G99ZGprKThNtetkO_6WVR0qxTXmHsJYnnoEdn5IY",{"id":361,"title":362,"body":363,"chapterName":99,"chapterNumber":100,"description":684,"extension":102,"includesCode":103,"lessonNumber":92,"meta":685,"navigation":105,"path":686,"seo":687,"starterCode":108,"stem":688,"tags":689,"__hash__":690},"lessons/lessons/1-02-intro-code.md","Introduction to C++ Code",{"type":8,"value":364,"toc":676},[365,367,370,374,377,381,384,393,430,435,444,453,456,460,470,479,488,491,500,511,514,517,596,599,603,620,655,664,668,671,674],[11,366,14],{"id":13},[16,368,369],{},"In this lesson, we'll cover the basics of programming in C++ and how to control your circuits with code. You'll learn\nabout\nvariables, functions, and how to write simple programs to interact with your circuits.",[11,371,373],{"id":372},"c-basics","C++ Basics",[16,375,376],{},"C++ is a powerful programming language that is widely used in embedded systems and microcontroller programming. It\nallows you to write efficient code that can run on small devices with limited resources. Here, you can define\nvariables to store data, call functions to interact with your hardware, and use control structures like loops and\nconditionals to control the flow of your program.",[11,378,380],{"id":379},"variables","Variables",[16,382,383],{},"Variables are used to store data in your program. You can define a variable by specifying its type and name, and\noptionally initializing it with a value. For example:",[269,385,387],{"className":271,"code":386,"language":273,"meta":91,"style":91},"int specialNumber = 4;\n",[40,388,389],{"__ignoreMap":91},[277,390,391],{"class":279,"line":100},[277,392,386],{},[16,394,395,396,399,400,403,404,407,408,411,412,415,416,419,420,422,423,425,426,429],{},"This line of code had a few key sections to it. First, we defined the type. In this case, ",[40,397,398],{},"int"," stands for integer,\nwhich is a whole number. Other types include ",[40,401,402],{},"float"," for decimal numbers, ",[40,405,406],{},"bool"," for true/false values, and ",[40,409,410],{},"char"," for\nsingle characters.\nNext, we gave our variable a name, ",[40,413,414],{},"specialNumber",", which is how we will refer to it in our\ncode. Then, we used the assignment operator ",[40,417,418],{},"="," to assign it a value of 4. This means that ",[40,421,414],{}," now holds the\nvalue 4, and we can use it in our program wherever we need to refer to that value.\nWe then gave it a value of 4. This means that ",[40,424,414],{}," now holds the value 4, and we can use it in our program\nwherever we\nneed to refer to that value. Finally, we ended the line with a semicolon ",[40,427,428],{},";",", which is used to indicate the end of a\nstatement in C++.",[27,431],{"alt":432,"src":433,"width":434},"Guide showing the parts of initializing a variable","/images/lessons/02-initialize-variable.svg","50%",[16,436,437,438,440,441,443],{},"In this example, we define an integer variable called ",[40,439,414],{}," and initialize it with the value 4. Later, if we\nwanted to change the value of ",[40,442,414],{},", we could simply assign it a new value like this:",[269,445,447],{"className":271,"code":446,"language":273,"meta":91,"style":91},"specialNumber = 10;\n",[40,448,449],{"__ignoreMap":91},[277,450,451],{"class":279,"line":100},[277,452,446],{},[16,454,455],{},"You can use variables to store values that you want to use later in your program, such as sensor readings\nor the state of a component.",[11,457,459],{"id":458},"calling-functions","Calling Functions",[16,461,462,463,466,467,469],{},"Functions are blocks of code that perform a specific task. You can call a function by using its name followed by\nparentheses ",[40,464,465],{},"()",". For example, if you want to set a digital pin to ",[40,468,42],{},", you might call a function like this:",[269,471,473],{"className":271,"code":472,"language":273,"meta":91,"style":91},"digitalWrite(3, HIGH);\n",[40,474,475],{"__ignoreMap":91},[277,476,477],{"class":279,"line":100},[277,478,472],{},[16,480,481,482,484,485,487],{},"In this example, ",[40,483,180],{}," is the name of the function, and we pass it two arguments: the pin number (3) and the\nvalue\n(",[40,486,42],{},"). This function would set pin 3 to a high voltage level, which could turn on an LED or activate another\ncomponent\nconnected to that pin.",[16,489,490],{},"When calling a function, it may also return a value that you can use in your program. For example, if you want to read\nthe value from an analog pin, you might call a function like this:",[269,492,494],{"className":271,"code":493,"language":273,"meta":91,"style":91},"int sensorValue = analogRead(2);\n",[40,495,496],{"__ignoreMap":91},[277,497,498],{"class":279,"line":100},[277,499,493],{},[16,501,502,503,506,507,510],{},"Here, ",[40,504,505],{},"analogRead"," is the function that reads the value from pin 2 and returns it as an integer. We store this returned\nvalue\nin a variable called ",[40,508,509],{},"sensorValue"," for later use in our program. We can use this returned result in place of a literal\nnumber.",[16,512,513],{},"Functions can take different numbers of arguments and can return values as well. You can use functions to interact\nwith your hardware, perform calculations, or organize your code into reusable blocks.",[16,515,516],{},"Here are a few more examples of function calls you might see in your code:",[147,518,519,536],{},[150,520,521],{},[153,522,523,527,531],{},[156,524,525],{},[159,526,161],{},[156,528,529],{},[159,530,166],{},[156,532,533],{},[159,534,535],{},"Example",[173,537,538,547,558,569,579,588],{},[153,539,540,542,544],{},[178,541,180],{},[178,543,183],{},[178,545,546],{},"digitalWrite(1, HIGH);",[153,548,549,552,555],{},[178,550,551],{},"digitalRead",[178,553,554],{},"Senses and returns HIGH or LOW from a specified pin.",[178,556,557],{},"bool isOn = digitalRead(1);",[153,559,560,563,566],{},[178,561,562],{},"analogWrite",[178,564,565],{},"Intstructs a pin to output an analog signal until changed. Accepts from 0-256.",[178,567,568],{},"analogWrite(1, 212);",[153,570,571,573,576],{},[178,572,505],{},[178,574,575],{},"Senses and returns from 0-1024 the signal strength from a specified pin.",[178,577,578],{},"int signal = analogRead(1);",[153,580,581,583,585],{},[178,582,191],{},[178,584,194],{},[178,586,587],{},"pinMode(1, OUTPUT);",[153,589,590,592,594],{},[178,591,202],{},[178,593,205],{},[178,595,208],{},[16,597,598],{},"There are many more functions available for you to use in your code, and we will go over some of these as they become\nrelevant in the upcoming lessons.",[11,600,602],{"id":601},"arduino-code-layout","Arduino Code Layout",[16,604,605,606,609,610,613,614,616,617,619],{},"When programming for microcontrollers, we typically have two main functions: ",[40,607,608],{},"setup()"," and ",[40,611,612],{},"loop()",". The ",[40,615,608],{},"\nfunction is called once when the program starts and is used to initialize your hardware and set up any\nnecessary configurations. The ",[40,618,612],{}," function is called repeatedly in a continuous loop and is where you will write\nthe\nmain logic of your program to interact with your circuits.",[269,621,623],{"className":271,"code":622,"language":273,"meta":91,"style":91},"void setup() {\n    // This code runs once when the program starts\n}\n\nvoid loop() {\n    // This code runs repeatedly in a loop\n}\n",[40,624,625,629,634,638,642,646,651],{"__ignoreMap":91},[277,626,627],{"class":279,"line":100},[277,628,282],{},[277,630,631],{"class":279,"line":92},[277,632,633],{},"    // This code runs once when the program starts\n",[277,635,636],{"class":279,"line":290},[277,637,293],{},[277,639,640],{"class":279,"line":296},[277,641,299],{"emptyLinePlaceholder":105},[277,643,644],{"class":279,"line":302},[277,645,305],{},[277,647,648],{"class":279,"line":308},[277,649,650],{},"    // This code runs repeatedly in a loop\n",[277,652,653],{"class":279,"line":314},[277,654,293],{},[16,656,657,658,660,661,663],{},"In the ",[40,659,608],{}," function, you might set pin modes, precalculate some numbers, or perform any setup tasks\nrequired for your project. In the ",[40,662,612],{}," function, you would write the code that controls\nyour circuits, such as reading sensor values, controlling LEDs, or responding to user input.",[11,665,667],{"id":666},"next-steps","Next Steps",[16,669,670],{},"In the next lessons, we'll be building projects that use the components in your kit and writing code to control them.\nYou'll learn how to read sensor values, control LEDs, and create interactive projects with your circuits. Remember to\nexperiment with the code and have fun exploring the possibilities of what you can create!",[16,672,673],{},"If this is your first time programming, don't worry if it feels a bit overwhelming at first. Programming is a skill that\ntakes\ntime to develop, and the best way to learn is by doing. Start with simple projects and gradually build up your skills as\nyou go. Don't be afraid to make mistakes and learn from them, and remember that there are many resources available\nonline to help you along the way. Happy coding!",[339,675,341],{},{"title":91,"searchDepth":92,"depth":92,"links":677},[678,679,680,681,682,683],{"id":13,"depth":92,"text":14},{"id":372,"depth":92,"text":373},{"id":379,"depth":92,"text":380},{"id":458,"depth":92,"text":459},{"id":601,"depth":92,"text":602},{"id":666,"depth":92,"text":667},"Learn the basics of programming in C++ and how to control your circuits with code.",{},"/lessons/1-02-intro-code",{"title":362,"description":684},"lessons/1-02-intro-code",[111,40],"_jD_UFJ2GGZGHQ267lTgrvLbNUzfuFk0B8ChjIbuNeE",1775950750365]