class: center, middle # Intro to Programming A Fab Academy Recitation by [Rodrigo Shiordia](https://www.instagram.com/rshiordia). --- # Overview * What is programming? * Code vs. Program vs. Algorithm * What does a program do? * The building blocks of programming. - Variables - Control Structures - Functions and Methods - Debugging - Libraries --- # What Is programming? * Programming is a way for us to tell computers what to do. * A computer is very fast, but also very dumb. * Computer programming is like giving instructions to someone, but you have to be very literal and describe everything in precise detail. The computer is incapable of understanding what you want, so you have to be very precise. --- # Coding vs. Programming * Coding is normally used as a synonym to programming. You code in python, C or C++ which are programming languages. * Programming is the logic behind the code. It refers to coming up with the ideas that you need to order in a code so that the computer understands and executes your intent. --- # How does a program work? * In the context of Fab Academy, we will use programs to tell MCU's to deal with inputs, outputs, and talk to other devices. * A program is written in source code. * Source code is compiled by a compiler into machine code. * Machine code is executed by the computer and we get a specific computing result. --- # The building blocks of programming. * Variables * Control Structures * Functions and Methods * Debugging * Libraries --- # Variables * A variable is a pointer to some memory location. Whe give it a name and store data to it. - variable data type - variable name - variable value  --- # Data Types * Data types are the "categories" that variables belong to.  --- # Using Variables //Explaining Variables //Rodrigo Shiordia 2023 int myAge = 37; float mySpeed = 1.5; bool isAlive = true; String myName = "Rodrigo"; void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: Serial.println(myName + " is " + myAge + " years old."); delay(2000); } --- # Flow Control * Control loops help us manage the Flow a program. * Flow control is about making decisions of when to do things or how many times do different things. * Using Flow control structures we can create more complex programs that can repeat code several times, check if a condition is met, do somehting in case something else happens, or read iteratively from a list, etc. * Common control structures are: * Conditionals * For loops * While Loops --- # Conditionals //Explaining Conditionals //Rodrigo Shiordia 2023 int myAge = 37; float mySpeed = 1.5; bool isAlive = true; String myName = "Rodrigo"; void setup() { Serial.begin(9600); } void loop() { if (myAge < 37) { Serial.println(myName + " is young."); delay(2000); } else if (myAge == 37) { Serial.println(myName + " is old."); delay(2000); } else { Serial.println(myName + " is veeery old."); delay(2000); } } --- # Functions and methods * Functions and methods are ways of reusing code. * Something that you are going to do several times, you can put inside a function and use it again and again. * A function normally has a return value: somehting that it returns back to you after you call or invoke it. (Some functions have no return value or a void return value.) ---