Students will learn how to apply the basic fundamentals of computational thinking (decomposition, pattern recognition, abstraction, and algorithms) to written code. This will equip them with the skills that necessary to code and debug the following Arduino lessons.
For each participant:
In general:
Computer (laptop or desktop)
Arduino IDE ready to go
functions
values (variables and constants)
structure
boolean operators
logical operators
loops
if/else conditional
bug/debugging
syntax
Maybe here would be a good spot to establish that computational thinking isn't just a CS skill, it is a skill that can be applied to all aspects of life. Kinda start breaking down what CS means, what CT means, and who can be good at CS and CT?? (EVERYONE!!)
The Arduino programming language is broken into three main parts:
functions: For controlling the arduino board and performing computations
values (constants and variables): Arduno data types and constants
structure: The elements of Arduino (C++) code
What does this mean?
A function is section of code that performs a specific task. To use a function, you must follow a specified syntax. Functions are useful because they allow us to execute a certain command without having to program that comman ourselves. For example, to find the sqare root of a number there is a function called "sqrt( )". If I wanted to find the square root of 25 I could type "sqrt (25)". When the computer reads this line, it calls the function called "sqrt( )" and executes all of the code in that function. This is helpful because I don't need to know the code that was executed, I just need the sqrt of 25 which will be returned.
There are specific types of values (listed on the Arduino website) that the Arduino IDE recognizes. Constants refer to static types, and they reference something that has a set value. Conversion can be used to convert one data type to another. Data types are different ways in which the data can be stored, they are like containers that can only hold a specific type. For example, the boolean data type is like a container that can only hold logic values, which would be the constatns true|false. Variable Scope and Qualifiers refer to the context in which the variables can be used. For example, if I create an integer variable "x" and I always want it to be set to the value 5, I could declare it as "const int x = 5;" by declaring it as const, the computer recognizes that I want x to always equal 5, and it will prevent me from changing the value of x anywhere else in the program.
Structure refers to the backbone/foundation of the language. It's like the alphabet, as it is the building blocks for all code that we will write. For example, some of the structures listed are arithmetic operators. That means if I want to find the remainder of 12 divded by 5, the structure for finding the remainder is "%" so I would have to code that as "12%5" and the computer would return 2.
There are many different programming languages which are useful for different applications. Arduino is based off of C++ (C plus plus), which means much of the Arduino syntax, data types, and strucure is similar to that of C++. If you run across a bug in your code or want to add an extra element, a quick Google search will return a number of resources to code or forums that explain a concept. It is important to make sure that you specify C++ or Arduino as the language, as ideas might be similar across languages, but the syntax will be very different. If you do not have the correct syntax, the computer will not recognize the command and an error will occur. This is similar to if you submitted a paper written in French for a German class. The ideas might be the same, but if it is written in the wrong language the computer won't understand.
Resource:
function - a block of code that performs a specific task
variable - a storage address that can be referenced to get the specific value stored there
constants - a value that is set and can't change
structure - the format that the data is stored and organized in
boolean operators - operators used with conditional statements, aka "logical operators"
loops - a group of code that is continually repeated until a specific condition is met
if/else conditional - a conditional statement that runs a different section of code depending on whether the conditional is true or false
bug - a flaw or error in the code. Either a logical error or a syntax error.
debugging - the process of detecting and removing bugs from a program
syntax - the spelling and grammer of a programming language
The following is an activity which explains loops, conditionals, and if/else statements in more detail. There are also questions which allow you to practice these new skills to help you master the basics.
Here is the answer key for the activity:
These are saved as PDFs, how do I insert them here?
option 1: if computer source do something with scratch or Arduino itself
option 2: if not computer have a thing here written out for them to follow on paper and pencil. Have them write instructions for a specific task. Attach a sheet that has a list of tips if they get stuck. ex: "did you check if each number is less than 10?"
provide examples of how to do the program, provide lots of comments explaining what each step is doing and why. Explain that there are infinite number of ways to achieve this blah blah.
As a bonus provide a debugging activity? Have like 5 lines of code and for each line they need to find the bug. Could be like what is the bug with this line? And the directions are like "increment every number greater than 5 by 1 and you could have: if(x < 5) x = x +1; The bug would be the (x<5). This could help participants learn how to look for both syntax errors and logic errors
References:
Add a ton of websites here for reference. If participants are doing this on their own at home they will need lots of references since this can be confusing stuff for newbies