Variables Lesson 3.

Slides:



Advertisements
Similar presentations
Balance Training Tower System Analysis Describing device to customer.
Advertisements

Introduction to TouchDevelop
Targeting Grade C Angles SSM1 GCSE Mathematics. Practice 1:: To recognise vertically opposite, alternate (Z), corresponding (F) and interior angles Practice.
Flowol subroutines Subroutines are used to:  Simplify your code to make it easier to read (or for someone.
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
Python Programming Using Variables and input. Objectives We’re learning to use basic knowledge of variables combined with user input. Outcomes Continue.
How many stars is a face worth?. Your turn Write down the equation each time you alter the scales. Remember to take the same things off each side!
Learning about LGBT young people Using software to create posters.
Hacking Minecraft on the Raspberry Pi using Python
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
Hacking Minecraft on the Raspberry Pi using Python Lesson 2 1.
Learning about LGBT young people Using software to create posters.
Variable scope. Variable Scope Variables do not live forever. Failing to take that into account leads to problems. Let's look at an example. Let's write.
Today you will: 1.Explain how the colours of objects depend on the colours in light which they absorb and reflect 2.Explain why objects appear to be different.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Scratch Programming Cards
GCSE COMPUTER SCIENCE Practical Programming using Python
CHAPTER 4 DECISIONS & LOOPS
Exploring Mathematical Relationships Module 5: Investigation 1
Broadcasting (Adding a new level)
Exploring Mathematical Relationships Module 5: Investigation 3
Building with Numbers Module 4: Investigation 3
Madlib-Input, Strings, and Lists in Scratch
Building with Numbers Module 4: Investigation 2 Timers and Stopwatches
Coordinates And Geometry Module 6: Investigation 1
Starter Activity Instructions: Complete the starter sheet Planner
Exploring Mathematical Relationships Module 5: Investigation 2
Computer Programming I
Programming Scratch to Control a K’NEX Fairground Ride
Lesson 4 – Glowing pendulum
Lecture 07 More Repetition Richard Gesick.
Basics for Robotics Programming
Creating Flowcharts AIM:
BBC Microbit.
Loopy Motion Control.
Print slides for students reference
BBC Microbit.
Programming In Lesson 3.
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Beginner Programming Lesson
Storing Values as Variables
Crossing the B-Line Start with all 6 Bricks on the red line – in any order Always move bricks in a straight line – from line to line.
BBC Microbit.
Recap the basics Lesson 1.
We’re moving on to more recap from other programming languages
Introduction to TouchDevelop
Program Documentation
Using the sensor Lesson 5.
Put it all together Lesson 5.
CSCI N207 Data Analysis Using Spreadsheet
Programming In Lesson 4.
An Introduction to VEX IQ Programming with Modkit
Clear and Unclear Windows
I can program behaviours using inputs and outputs
Put it all together Lesson 6.
Variables Lesson 3.
Coding Edbot Dream with Scratch
Recap the basics Lesson 1.
Basic Lessons 5 & 6 Mr. Kalmes.
Using the sensor Lesson 5.
I can control a motor and use a sensor
I can control multiple outputs with a sensor
I can program behaviours using inputs and outputs
Lesson 3-2 Isosceles Triangles.
Lego MINDSTORMS EV3.
3.2 Working with Data Scope of variables 29/07/2019.
Presentation transcript:

Variables Lesson 3

Starter What will this program do? What is a variable? What is the variable in this program? How do you create variables?

Objective of the lesson Use variables in your programming All of you will: Explain what a variable is used for Most of you will: Switch servo motors on and off Manipulate parts of Edbot and save the servo positions as a variable Some of you will: Use variables and mathematical operators to work out the average of 3 numbers entered

Alter this program What will this program do? Open L3_Average.sb2 and enter the program. Change the program so that it will work out the average of the 3 numbers that have been entered and then ask the user to enter the average (the total divided by 3).

Possible answer

Recap on servos What are servos? What would servos 1 and 2 control? Servos are set to positions from 0 to 300 and servos 1 and 2 move Edbot’s arms from the shoulder.

Using Servos Open the program called L3_Mirror.sb2. This program has been started for you and will set Edbot to the initial position and then turn servo 1 off. This will switch off servo 1’s motor so you can manipulate it manually. Create a new variable called servoposition and set it to 0. What will this line of code do?

Servos The servos on each side work by rotating between 0 and 300. Opposite servos will need to use opposite values on the 0 – 300 scale. Therefore if servo 1 is set to 50, to make servo two move to the same position it will need to be set to 250. We want servo 2 to move so that it is at the same angle as servo 1. How can we do this? Why does this need to be inside a forever loop?

Altering your script We only want it to run this code if servo 1 has moved. Write an if statement so that if servo 1 position is over “servopostion + 1” OR servo 1 position is under “servoposition – 1” then it will set servopostion to Edbot’s servo 1 position and move servo 2 so that it mirrors this movement.

Remember you can create your own blocks Last lesson, we looked at how you can create your own blocks. Why would you create your own blocks? How can you create a block? How can you use that block in your programming?

Over to you… Create a block called “Getservonum” which will ask the user to enter a number. If they answer below 17 display the message “Thank you” and save their answer in a variable called “servonum”. However, if their answer is not below 17 say “Incorrect” and set the servonum variable to “all”. In the main program set Edbot to the initial position and set all the servo colours to off. Run the Getservonum block and set servonum to red for 1 second then switch all the servo lights off again. Run the Getservonum block again but this time set the servonum to green for 1 second. Run the Getservonum block a third time but this time set servonum to yellow for 1 second before you switch all the servo lights off again.

Possible answer Here you can see we have defined a block “Getservonum” and it is used 3 times in the program to get the servonumber. The variable “servonum” that is generated from that block is used in the main program.

Self-assessment Read the highlighted points and tick those that you feel you have achieved.