Programming Scratch to Control a K’NEX Fairground Ride

Slides:



Advertisements
Similar presentations
Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
Advertisements

You need to press F5 to start Multimedia Presentations Making things a little more interesting Multimedia Presentations.
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Audacity Lesson One Venette Cook What will we do? 1.Open Audacity on the desktop. 2.Record your voice! 3.Save on your flash drive. Give a title. 4.Export.
JED Microprocessors Pty Ltd Presenting the JED T430 low-cost Projector Controllers Nov 22nd, 2009.
Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
Bug Session One. Session description In this session, pupils are introduced to a programming sequence which will make a light pattern on their Bug. Objectives.
Harry Potter Scratch Game
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
Embedded Programming and Robotics
Bug Session One. Session description In this session, pupils are introduced to a programming sequence which will make a light pattern on their Bug. Objectives.
Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
Programming 101 The Common Palette Content provided by Connor Statham (6 th Grade Student) Formatting by Shannon Sieber.
Code Club Session 2 Dance Party. What will we learn ?  How to change the background  How to create animations  How to make objects talk to each other.
Introducing Scratch the Cat
Reactive robots UPNA The Public University of Navarra Material for pupils & students.
How to make a Shooting Target game in Scratch!. WE ARE GOING TO MAKE A TARGET GAME. This game will have: A Target that will move when clicked. A Timer.
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
L ILY P AD T RAINING C ENTENNIAL E LEMENTARY 2012 Material by Linz Craig Revision by Sarah Bloms Additional images by Modkit & Adam Meyer.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
1 Understand how to use Scratch to: – Animate a sprite – Add sound to your script – Use the forever command to create a loop Lesson 2: Learning Objectives.
Motors and Sound Troubleshooting Tips. © H-CCS Problem 1 Why can’t I download my program to the RCX?
The If Block. IF The “if” block can be found in the control tab. The if block means, “IF this happens, THEN do this.” You can put blocks ON the if block.
24 Background Building 25 Computing Terminology, and Speed/Velocity Module 4 Notes: Sensing, Or Operator, Conditional Logic 28 Module 4 Algorithms,
Lets Go Green!. Step 1 Save paper by using USB flash drive. Insert into copier, it’s easy!
Using MIT Scratch for Programming and Control Exercise 1 Creating movement Year 11 DTG 2012.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high x increasesx decreases.
Hacking Minecraft on the Raspberry Pi using Python Lesson 2 1.
Testbed Coding In this activity you will code different challenges for the Testbed. For each challenge a sample program is shown. Use what this sample.
Programming and Debugging with the Dragon and JTAG Many thanks to Dr. James Hawthorne for evaluating the Dragon system and providing the core content for.
Testbed Coding In this activity you will code different challenges for the Testbed. For each challenge a sample program is shown. Use what this sample.
Scratch Programming Cards
Having fun with code, using Arduino in a middle school CS classroom
Programming and Debugging with the Dragon and JTAG
Scratch for Interactivity
Scratch Unit Overview We are going to look at computer programming and how to create your very own computer game The piece of software we will be using.
© A+ Computer Science -
Scratch: iteration / repetition / loops
Stop Light Lab 7 Winter Quarter.
Basic Troubleshooting Techniques
Unit 2 Getting Started With
Lighting LEDs with a RASPBERRY PI
Basics for Robotics Programming
Loopy Motion Control.
Introduction to Object-Oriented Programming
Raspberry Pi: External Inputs & Outputs
Traffic light programming challenges
Raspberry Pi with Pibrella
Welcome to Digital Electronics using the Arduino Board
Objective of the lesson
An Introduction to VEX IQ Programming with Modkit
Line Following Behavior
Go to =>
Recap the basics Lesson 1.
Go to =>
Go to =>
While Loops and If-Else Structures
Recap the basics Lesson 1.
© A+ Computer Science -
Arduino Uno circuit basics
Makey Makey!.
Creating a Simple Game in Scratch
Task 1 You are going to use the Makey Makey arrow inputs to create a joystick / games controller. Step 1: Connect Makey.
Oregon Robotics Tournament and Outreach Program
Interface ckt for demo Outputs Inputs V PIN 0 10K PIN 4 GND GND
Objective of the lesson
Introduction to Programing the Cortex for BEST
Presentation transcript:

Programming Scratch to Control a K’NEX Fairground Ride

Raspberry Pi and K’NEX System K’NEX Model PiFace Raspberry Pi Motor Speaker LED Lights Switch

Computer Control Parts Scratch Raspberry Pi PiFace

How does Scratch control the motor, lights and mini speakers? Scratch Handler Switch Lights Motor Speakers KNEX Model Raspberry Pi PiFace Key = Software Hardware

How does Scratch use the switch to control the lights and motor? 1. Press the switch. Scratch gets to know by a certain variable being set to 1 Scratch Handler Switch Lights Motor Speakers KNEX Model Raspberry Pi PiFace 2. The Scratch program decides what to do and sets variables to tell the lights and motor what to do

Example Code

PiFace When “piface-output-3” is set to 1 These turn on 1 2 3 4 5 6 7 8 These turn on If an LED light is connected, it turns on

Computer Models and Computer Simulation Forecasting (Computer Model: sky conditions above the UK) Computer Aided Design (Computer Model: printed circuit board) Computer Model = Computer’s internal way of representing the real world objects Computer Simulation = Running a program that uses the computer model to predict how the real work objects will behave

Computer Models and Computer Simulation Why do we create computer models and run simulations? Because it’s too difficult, too slow or too expensive to use the real thing To predict what will happen in the future, or predict how something will behave

Modelling and Simulating the System using Scratch The Scratch file “Fairground Ride.sb” file contains a model of the switch, lights and motor When you set certain variables, the model will simulate the real switch, lights and motor.

Switch Code you put here runs when you press the switch the first time 1 2 Code you put here runs when you press the switch the first time 1 Code here runs on 2nd press Press and release once 1 Press and release second time 2 3 Press and release third time 3 Code here runs on 3rd press Press and release fourth time 1 1 Each time you press the switch it runs the next bit of code, then goes back to the start

LED Lights Turn on red light 1 Turn on red light 2 Turn on yellow light 1 Turn on yellow light 2 Turn on green light 1 Turn on green light 2 If you wait between the “set” commands, the program will be less likely to hang. If you do too many things at the same time, the PiFace can’t supply the electric current and it stops the Raspberry Pi. You will then have to reboot it. Turn off red light 1

Motor Set one of the variables to 1 and the other one to 0 to make the motor run Swap the numbers over to make the motor run in the opposite direction Set both the variables to 0 to turn the motor off. (Setting them both to 1 also turns the motor off). Don’t forget to wait between the two “set” commands

Sound You can use the sound commands to play music or make other sounds on the mini speakers. The Raspberry Pi is not very good at sound processing, so the sound you get will be slightly distorted.

Stopping a Loop If you use a “forever” loop, it will never finish, even if you press the switch again. It will only stop when you press the red stop button at the top right in Scratch. If you want the loop to finish when the switch is next pushed, you need to create a variable (e.g. “stop”) and use that to control the loop. Experienced programmers are all expected to use repeat-until loops in their programs

Open the Start Scratch File Run up Scratch and open “Fairground Ride.sb” from the Pupils’ Share. The Pupils’ Share can be found by clicking on the arrow to the right of Scratch Project, and then selecting drive I:

Writing the Scratch Program The Scratch file is already set up to connect to the PiFace. Click OK. Click on the “Model” sprite All your code should go into one sprite. If you are interested, you can look at the other three sprites, but don’t change them. Put you own code under the three “when I receive” blocks

Simulating the System Simulate your program by pressing “s”. This does the same as pressing the switch in the real system. The button on the switch on screen will look as though it has been pressed, and the number will change. The lights on the screen will come on and off just as the real ones will. The motor will animate to turn one way or the other when the variables are set up to turn it on. Sound will come out of the computer speaker. When you use the mini speaker on the Raspberry Pi, the sound will be a slightly distorted version of this.

Saving the Program Use File / Save As to save the program onto a memory stick. Save the file to drive E: which is where the USB memory stick is. Put your names into the filename, so we can see which group wrote each program later. You will use the memory stick later to copy the program onto the Raspberry Pi.