You are on page 1of 6

4th Grade Robotics Intro to Sysnthesis

Project Joystick

4TH GRADE ROBOTICS INTRO TO SYNTHESIS PROJECT


JOYSTICK

Throughline: How can software and programming help us communicate with hardware?
Write your answer here:

In this activity you will learn how to correctly


create code to use a Joystick to control LEDS.

1. Step 1: Open Mblock on your computer. If you do not have


it installed on your computer you can alternatively go to this
website link: https://ide.mblock.cc/?nav

2. Step 2: Enter your name and grade group in the blank


shown below. Afterwards, click on the “Save” button shown
below.

3. Step 3: Choose the file folder you want to save your Mblock
file to and then click on “Save”
4th Grade Robotics Intro to Sysnthesis

Project Joystick
4th Grade Robotics Intro to Sysnthesis
Project Joystick
4th Grade Robotics Intro to Sysnthesis
Project Joystick

4. Step 5: Name your variables. Create variables named: LED


1, LED 2, LED 3, LED 4 and X=A0, Y=A1
Notice that we are using the variables that we associated
with their digital pins to tell Arduino Uno that we want the
output to be either High or Low.

5. Step 9: Inserting the “Repeat” Function block. This tells


Arduino Uno to repeat reading the blocks of code in this
block from start to finish or until we write code which tells
Arduino Uno not read it or do something else. In this case,
we are telling Arduino Uno to read the blocks of code inside
of this block to repeat forever.
4th Grade Robotics Intro to Sysnthesis
Project Joystick

6. Step 10: Setting X and Y Axis pin Variables. In this block of


code, we are setting our Axis Y(up and down) or X(right and
left) to the Analog pins on our Arduino Uno.

7. Step 11: In this block of code we see several things


happening: 1. We see that there is an If / Then statement
with Else. This is called a conditional statement. For
example, “If it rains outside today, I will not go outside to
play football” so “Then” I will go inside and study and play
video games” “Else” means that if the above “If / Then”
statement is not true, then we will do something else. For
example: Because it is not raining outside, I will go outside to
play football with friends or ride my bike.
So the condition that exists is that IF it is raining outside I
will study and play video games, but IF it is NOT raining
outside, I will football with my friends or ride my bike.

4th Grade Robotics Intro to Sysnthesis


Project Joystick
8. Step 12: These blocks of code show that IF the variable
X=A0 is Greater than 800 (a value of how far the joystick is
moved in one direction or another.) Each Axis has a range
from 0-1023 read range which means that the output from
the Joystick for both X and Y Axis is from 0 (no output) to
1023 (maximum output).

This means that Arduino Uno can read a value from the
analog pin in a range from 0-1023. In the case below we are
telling Arduino that if it sees a value from the variable of
greater than 800, to set the output of digital pin 11, which is
connected to LED 2, to High output.

If this is not the case, then the output is set to Low. This
means that at a low setting there will not be any output to
the LED and it will not light up.

4th Grade Robotics Intro to Sysnthesis


Project Joystick
9. Step 13: Complete the code with the blocks shown below.
Now it is time for you to complete the code for the Joystick.
Make sure to pay attention to all details of the blocks of
code. If any of your code is wrong, you will not get the
correct results in the next activity of assembling and
connecting your Arduino Uno.

4th Grade Robotics Intro to Sysnthesis


Project Joystick
Step 14: Upload the Mblock code file into this Teams
Activity.
Click “Turn In”

You might also like