CR102 Tutorial – Class 1

Welcome to the first tutorial for the CR102 course. This lesson is a bit shorter and will primarily be review of CR101, but will also introduce flowcharts and loops.

Before you read this tutorial, it is highly recommended that you read the CR101 Tutorial if you have not already.

Review of CR101

  • Input is when the microcontroller is reading information from the outside world such as a button
  • Output is when the microcontroller displays information to the outside world
  • CarduBlock is a graphical programming language for Arduino
  • You need to do the following two steps every time you start programming an Arduino board or else it might give you an error when you upload your program to the board.
    • Go to Tools > Board > Select “Arduino/Genuino Uno”
    • Go to Tools > Port > Select the COM port for your Arduino
  • “If” and “Else” allows programs to make decisions, similar to asking a yes or no question

REVIEW PROJECT: Using servos, LEDs, and buttons, create a program that causes each button to light up its respective LED and puts the servo in a different position

Which button is pushedWhich LED turns onServo turns to
RedRed
GreenGreen90°
BlueBlue180°

Flow Charts

As the programs we write grow more complex, it quickly gets harder and harder to keep track of everything mentally. So, we will have to start planning our ideas before we actually program. The most common way of doing this is with flowcharts, which allow us to visually represent the order of events in a program.

  1. Loops

We already know one type of loop, which is the block that is required to run any CarduBlock programs. However, we will now be using more loops that we can manually insert into our program. These are found in the yellow Control bin.

The first loop we’ll be looking at is the repeat loop. This loop repeats anything programmed inside of it for a set number of times. For example, if we have a red and green LED and we want to flash the red one 5 times then the green one 5 times, we can use two repeat blocks, one after another, to reduce the amount of programming we have to do. It is very similar to a for loop, but an actual for loop would be the “repeat between” block.

The second one is the while loop. A while block repeats anything programmed inside of it until a certain condition is no longer true. For example, we can program a rover with a while loop that tells it to go forward while there are no walls in front of the rover. If there is a wall, the condition is no longer true, so the program exits the while loop. Note that you can sometimes use an “if” statement and the result will be the same; in programming, there can be a lot of different solutions to the same problem.

CHALLENGE:  Build a program to follow this flow chart.

CR102 Tutorial - Class 1

That’s all for this lesson! Look forward to the second one.