---
# System prepended metadata

title: IB Computational thinking using arduino
tags: [IB, Computer Science, Arduino]

---

# IB Computational thinking using arduino 

###### tags: `IB` `Computer Science` `Arduino`

[ToC]

Now that we have scratched the surface of doing a simple blink in arduino we can talk about **coputational thinking** in IB. 

This is a way of thinking that sometimes is useful in other circunstances, sometimes is a very bad idea to apply in other circunstances. 

This is to show you a specific mindset that you will help you. [It's like giving you a hammer. ](https://en.wikipedia.org/wiki/Law_of_the_instrument)You will tend see that everything is something to pound. 

![](https://i.imgur.com/BsDWyMw.png)


Given that warning I'm tell you what the nails that you're going to pound. 

**problems**

And the solution that you're going to use are

**algorithms**

So let's try to define both of them. 

## Problems

In Computer Science many things can be seen as problems and a problem is something that we need to deal with or solve. _(with an algorithm)_

Sometimes the problem is easy and well defined. I'm going to give you the task of express your name using morse code. You will have to order automatically some data. You have to do an Spanish Omelette. 

Sometimes the problem is not well defined and part of it is define it. 

* Making a new videogame. Which genre is going to be? what platform? 
* Creating a new database. Which kind of database? How do we interface with it?
* Doing a new website. For who is that website. What are the requirements?

Pay attention because your IA (Internal Assessment) is about _this_. We need to define problems and go into the specifics. 

Even in the example of the Spanish Omelette we can define a bit more the problem answering these questions:
* For how many people is the omelette?
* Are we using onion or are we _going barbaric_?
* Is there any other ingridient that we want to use?

In the case of the morse code we can define more the problem by stablishing some other boundaries
* Is the name going to be repeated forever or is it going to appear just once?
* In the case that is going to be repeated forever, how do we stablish when is the sequence begining?
* Are there any other feature that we want to include? (not for now)

There are other problems that cannot be solved using algorithms. Apart from the Spanish Omelette that it's a bit hard (but feasable):

{%youtube xoiII_c0_GE%}

For example we cannot use an algorithm to define "justice" or we cannot achieve the requirements for something that sounds feasable like voting. 

{%youtube LkH2r-sNjQs %}

Sometimes we don't know how to solve it, that happens in Math problems and also in some social science and of course philosophy. 


### Homework 1:

In your daily live you have programs that do things for you. Some programs are very large and complex, even if they are easy to use (tiktok, youtube). Some others are very simple (like an alarm clock) or they form part of bigger programs (spoiler, we're going to get there). 

Identify 3 problems and the programs/parts of programs that solve those problems. You need to identify it and give it some features that you expect from the program that it solves it for you and the program(s) that solve it .  (examples: mail, apps, cooking, online bots)

Identify 2 problems that are **not** solvable using an algorithm. Justify your answer. 


## Algorithms

(page 177 and following)

The solutions that we're going to use for our big or small problems are algorithms. Algorithms are series of unambigous instrutcions. 

We are used to algorithms.Let's see some examples of algorithms that you're familiar with:

### Recipe algorithm

There is a commonplace to make equivalence between programming an recipes and it's because recipes are algorithms. They are instructions that go in a sequence to achieve a specific goal (a dish). 

{%youtube DZrxTyGbzYI %}

This comparation also works with a concept. In some complex dishes (for example: Ramen or a lemon pie) you might need to know some other techniques that they need in order to do them (boil an egg or make meringue). 

### Math algorithm

You might recognize functions from Math

$$f(x) = x^2-3x+6$$

A function _is_ an algorithm that converts an input (in this case $x$) into an output ($f(x)$).

Sometimes is easy to see as an input-output. There is an input ($x$) and there is an output ($f(x)$). Sometimes is harder to spot those inputs and outputs. 

### Arduino algorithm

Here we can put our sketches of arduino. Let's see how they are set. 

In arduino, in any sketch we have 2 functions with brackets. 

void setup() that is going to execute one line by one once and only once at the start of connecting the arduino to the power.  

void loop() that is going to execute one line by one after the setup and it's going to repeat itself indefinitely (on loop).

### Social media algorithm (tik tok, youtube, instagram)

You can think of the _algorithm_ as the program that decides what to offer you in the social media. 

It's not trivial. What does it take into account?

What is the input of that algorithm? What is the output?

How do we write an algorithm?

We can use a flowchart method. We can draw it and we can use pseudocode. We can even describe it with words or make a video about it. Also some algorithms can be written in form of math functions or specific diagrams. 

Now let's try to write some algorithms down. Let's see as an example the algorithm that I follow before I arrive to the school every day. 

* I put down the alarm
* I go to the bathroom
* I take a shower
* I put some clothes
* I prepare my breakfast
* I clean my teeth
* I take my bike to the station
* I arrive to Mongat Nord
* I walk up the hill to arrive here

This is the basic stuff. We could go (and we will) deeper than this and we will add some caveats. 

### Homework 2.

Write the algorithm of your morning. You can use this written example of mine or you can use other systems of representation. 

You can use https://app.diagrams.net/


## Continuation

We are going to get deeper in how to describe the algorithms since it's a vital part in the exams and in the sillabus. 

* Characteristics
* Details of how to express them
* Adding decision making in the process