Lesson 5: LDR Control

Similar documents
Lesson 4: Animation. Goals

Lesson 8: Simon - Arrays

StenBOT Robot Kit. Stensat Group LLC, Copyright 2018

Arduino IDE Friday, 26 October 2018

Halloween Pumpkinusing. Wednesday, October 17, 12

Arduino Programming and Interfacing

Sten-SLATE ESP Kit. Description and Programming

Prototyping & Engineering Electronics Kits Basic Kit Guide

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

Counter & LED (LED Blink)

Adobe Dreamweaver CS5 Tutorial

Interactive Tourist Map

ROBOTLINKING THE POWER SUPPLY LEARNING KIT TUTORIAL

How to set up an Amazon Work Profile for Windows 8

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

Required software. Mac OS X In this section, you ll find instructions for downloading and configuring the Arduino IDE in Mac OS X.

ADOBE DREAMWEAVER CS4 BASICS

Connecting Arduino to Processing

Teacher Cheat Sheet - Game Coding Challenges

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

To lead your students through this activity, you will need your computer, attached to a projector, for projecting your code for students to see.

Lecture 7. Processing Development Environment (or PDE)

Adobe Dreamweaver CC 17 Tutorial

Your First Windows Form

Creating a Custom Report

1 Getting started with Processing

Beginning Mac Programming

How to make a Work Profile for Windows 10

Elektor Uno R4 Installation & Test

Lab: Supplying Inputs to Programs

Word 1 Module 2. Word 1. Module 2

Serial.begin ( ); Serial.println( ); analogread ( ); map ( );

Procedure: Determine the polarity of the LED. Use the following image to help:

My First iphone App. 1. Tutorial Overview

EXCEL BASICS: MICROSOFT OFFICE 2010

TA0297 WEMOS D1 R2 WIFI ARDUINO DEVELOPMENT BOARD ESP8266

Introduction to Microsoft Word 2010

ISL RGB Sensor Tutorial By: Sabrina Jones

Grade: 7 Lesson name: Creating a School News Letter Microsoft Word 2007

Connecting Arduino to Processing a

Parts List. XBEE/Wifi Adapter board 4 standoffs ¼ inch screws Cable XBEE module or Wifi module

A TUTORIAL ON WORD. Katie Gregory

ToyBox Futuristi Instruction Manual

Introduction to Microsoft Office 2016: Word

Objectives: Learn how to input and output analogue values Be able to see what the Arduino is thinking by sending numbers to the screen

Installing Microsoft Desktop Connection for MAC YOU RE USING THE MOST RECENT COPY (SEE LINK) OF MICROSOFT

ENGAGING SOLUTIONS MOBI and Workspace Beginners Manual

Introduction to Processing

Click Here to Begin OS X. Welcome to the OS X Basics Learning Module.

My First Cocoa Program

Arduino Prof. Dr. Magdy M. Abdelhameed

Circuit Playground Firmata

EXCEL BASICS: MICROSOFT OFFICE 2007

Station Automation --W3SZ

Iconasys Advanced 360 Product View Creator. User Guide (Mac OSX)

Parts List. XBEE/Wifi Adapter board 4 standoffs ¼ inch screws Cable XBEE module or Wifi module

Megamark Processing 3.0 Setup Guide. Downloading and Installing Processing 3.0

Getting Started with Energia for MSP432 LaunchPad

Robolab. Table of Contents. St. Mary s School, Panama. Robotics. Ch. 5: Robolab, by: Ernesto E. Angulo J.

ENGL 323: Writing for New Media Repurposing Content for the Web Part Two

Introduction to Microsoft Excel 2007

Sten-SLATE ESP. WiFi

Teach Yourself Microsoft Office Access Topic 2: Getting Started with Microsoft Access

Digital Video Surveillance User Guide

Module 2, Add on lesson Introduction to the NXT and Mindstorms software. Student. 45 minutes

Beginner Workshop Activity Guide 2012 User Conference

Microsoft PowerPoint and Digital Photos

Code&Drive First steps

Introduction to Computers By Jennifer King, YA and Marketing Librarian, Great Bend Public Library

This is the Arduino Uno: This is the Arduino motor shield: Digital pins (0-13) Ground Rail

Necessary software and hardware:

CTEC 1802 Embedded Programming Labs

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Arduino 01: Installing the Arduino Application and Firmware. Jeffrey A. Meunier University of Connecticut

Microsoft Office Word. Part1

The Big Idea: Background: About Serial

INTRODUCING THE CODEBIT!

QUICK GUIDE FOR STARTING A NEW PREMIERE ELEMENTS PROJECT

A Document Created By Lisa Diner Table of Contents Western Quebec School Board October, 2007

Lab-3: LCDs Serial Communication Analog Inputs Temperature Measurement System

Directions for Setting up Remote Desktop Connection for PC:

Excel. module. Lesson 1 Create a Worksheet Lesson 2 Create and Revise. Lesson 3 Edit and Format

Recording Auditions with Audacity

Computer Basics. Need more help? What s in this guide? Types of computers and basic parts. Why learn to use a computer?

Scratch 2.0 Wireless Programming Guide for Vortex

HYPERSTUDIO TOOLS. THE GRAPHIC TOOL Use this tool to select graphics to edit. SPRAY PAINT CAN Scatter lots of tiny dots with this tool.

Computer Basics. Hardware. This class is designed to cover the following basics:

Computer Essentials Session 1 Lesson Plan

Lesson 4: Introduction to the Excel Spreadsheet 121

CS12020 (Computer Graphics, Vision and Games) Worksheet 1

Premiere - Jazz Video Project Tutorial

COMP : Practical 6 Buttons and First Script Instructions

Navigator Update to Software Instructions TABLE OF CONTENTS SECTION 1 DOWNLOAD FILES... 2 SECTION 2 UPDATE BOX SOFTWARE...

NAME EET 2259 Lab 3 The Boolean Data Type

PediGait IP. Users Manual

Basics. Mouse The mouse normally looks like a little arrow, but it can change depending on what you are doing

SenCom Jan. 11, 2013 Demonstration on Windows 7 Desktop, Windows Explorer & File Mgmt., and using Thumb/Flash Drives These topics by Mike Smith

The Fundamentals. Document Basics

Lutheran High North Technology The Finder

EEG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

Transcription:

Lesson 5: LDR Control Introduction: Now you re familiar with the DIY Gamer and editing in an Arduino sketch. its time to write one from scratch. In this session you will write that talks to the Light Dependent Resistor getting it to control the playback of an animation on the LED Display. This could be a pre made animation, the one you created last session, or you can make a new one from scratch. Goals Monitor light values from the Light Dependent Resistor (LDR). Use the changing light values to control an animation. this Test your Project Save Save your project Page 1 -

Step 1: Write your essential scripts 1. Open up the Arduino Software 2. Open a new sketch 3. Import the DIY Gamer library This includes a library that allows us to talk to the gamer. It should already be installed so we can import it from the sketch menu. To import the library go to sketch > import library > Gamer It will look then like this at the top of the sketch. #include <Gamer.h> 4. Create a New gamer object This creates a new object that contains all of the DIY Gamer library functions, and we are going to call it, gamer. this below your imported gamer library. #include <Gamer.h> Gamer gamer; Page 2 -

Step 1: Write your essential scripts 5. set up script This is the setup script that happens once at the beginning. Inside the curly bracket is where we setup any functions that we are going to use. #include <Gamer.h> Gamer gamer; void setup() { 6. the void loop function This is the start of our basic loop which will be happen infinitely or until the DIY Gamer runs out of power. the following after your setup. void setup() { void loop() { Page 3 -

Step 1: Write your essential script 7. Edit setup script between curley brackets This tells the gamer object to start doing all of it s button sensor handling functions, and opens up a connection with the serial port with a speed of 9600. void setup() { gamer.begin(); Serial.begin(9600); Test your project 8. Test your Click to verify that everything that has been typed so far is understood. It should say done compiling in the bottom menu bar if successful. Errors? Check for: 1. Missing capital letters 2. Missed or wrong brackets 3. Missed semi colons. Ok, so that is the basic structure in place, we can start to pad it out to make it do the interesting stuff. Page 4 -

Step 1: Write your essential script 9. Monitor LDR output Edit the void loop function. void loop() { Serial.println(gamer.ldrValue()); delay(10); This outputs the light reading from the LDR to the serial monitor every 10 milliseconds, i.e how much light is hitting its surface and then converting that to a number. Test your project 10. Test your Click verify to check that everything typed so far is understood. 11. Go to Menu > Tools > Board > Arduino Uno This checks that we have the right Arduino board selected 12. Go to Menu > Tools > Serial Port > USB Select the port that the Arduino is connected to. This name should be something like /dev/tty.usbmodem on a mac, or COM3 or higher on a PC. Page 5 -

Step 1: Write your essential script Test your project 13. Test your Click to transfer the onto the Arduino in the DIY Gamer. The red LED should be blinking to show a transfer is taking place. The screen will be blank, but the DIY Gamer is working. 14. Click on magnifying glass in top right corner to open serial monitor The serial monitor is a window that lets the Arduino communicate with us and tell us information about what is going on in the. We asked the Arduino to tell us the LDR value (how much light the LDR is detecting). This should now be shown as a stream of numbers in the serial monitor. Put your hand over the LDR, the numbers go up in value. Take your hand off, the numbers go down in value. 15. Write down highest and lowest values of LDR Cover the LDR with your thumb. Write down the lowest reading here. Uncover the LDR. Write down the highest reading here. These are important, we are going to use these numbers to control our animation. The numbers we are using in this example are 200 and 860, which is a room lit with lightbulbs. Page 6 -

Step 1: Write your essential script 16. the following above the setup script int currentframe; void setup() { This is a variable that stores the current frame of which our animation is going to play. Save Save your project Click the arrow facing downwards that looks like this to save your. Call your project YourNameLDR. It will save to the Arduino folder. Page 7 -

Step 2: Control the screen using the LDR 1. Open > Gamer > AnimationWithLDR Click up arrow icon to open sketch from Arduino folder 2. Can you find the Void setup? This set up all the functions the gamer needs. void setup(){ //Set up Gamer gamer.begin(); Page 8 -

Step 2: Control the screen using the LDR 3. Can you find the Void loop? This is the main part of the that is looped through over and over again. void loop(){ //Convert LDR value to a frame. currentframe = map(gamer.ldrvalue(), 0, 1023, 0, NUFRAMES); //Print current frame! gamer.printimages(frames[currentframe]); delay(10); 4. Can you find the Arrays? These 8 rows of 8 one s and zero s are the part of the which tell the Gamer s LED matrix which LEDs to turn on or off. They directly represent the DIY Gamers screen. 5. Remember how the 1 s represent a pixel that is on? Page 9 -

Step 2: Control the screen using the LDR 6. Select the arrays by clicking and dragging with your mouse Select ALL the arrays down from and including: # define NUMFRAMES #define NUMFRAMES 6 byte frames[numframes][8] = { {B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000, {B00000000, B00000000, B00100100, B00011000, STOP BEFORE YOU GET TO THE VOID SETUP CODE, you need this! void setup(){ //Set up Gamer gamer.begin(); 7. Copy the selected arrays Go to edit > copy. Or use the shortcut cmd + c (mac osx) or ctrl + c (Windows) 8. Open > yournameldr sketch Click up arrow icon to open sketch from Arduino folder. This will open the LDR animation sketch you were just working on. Page 10 -

Step 2: Control the screen using the LDR 9. Edit the sketch This is where you want to paste the arrays you just copied. int currentframe; PASTE HERE 10. Paste using: control V (PC) command V (mac) This will paste the pre made sun animation arrays into the sketch. 11. Edit void loop the following at the start of the void loop. This is where you need to use the LDR values that you wrote down earlier. The values you need to change to your own are circled below in blue. void loop() { currentframe = map(gamer.ldrvalue(), 200, 860, 0, NUMFRAMES); This line of maps (using clever maths) the Light reading to the number of frames in your animations. Fully uncovered, the LDR will display the first frame of the animation. Fully covered up, it will show the last frame. Page 11 -

Step 2: Control the screen using the LDR 12. Edit void loop (continued) Look at the example below to give you an idea of how it works. Remember to use the light readings from the space you are in! Light on LDR 200 330 460 590 720 850 LDR light reading 0 1 2 3 4 5 Frame no. Game DIY Gamer screen 13. in your void loop script on next line void setup(){ //Set up Gamer gamer.begin(); Serial.begin(9600); void loop(){ //Convert LDR value to a frame. currentframe = map(gamer.ldrvalue(), 0, 1023, 0, NUFRAMES); //Print current frame! gamer.printimage(frames[currentframe]); Serial.println(gamer.ldrValue()); delay(10); Page 12 -

Step 2: Control the screen using the LDR Test your project 14. Test your Click verify to check that everything typed so far is understood and has compiled successfully. 15. Upload to Gamer Click to transfer the onto the Arduino in the DIY Gamer. The red LED should be blinking to show a transfer is taking place. The screen will be blank, but the DIY Gamer is working. 16. Test on DIY Gamer Put your thumb over the LDR on the DIY Gamer and see what happens. The animation should now be on its first frame if the LDR is detecting light, and progress through the animations frames to the final frame when it is fully covered and in the dark. Errors, check your light readings. Perhaps try entering ones that are 50 higher and lower that your readings to provide a safety margin. Challenge: How could you make the same animation play backwards, so it is at the end of the animation when receiving light? Well Done You have just d the DIY Gamer to use its LDR to control an animation. Awesome! You are now well on your way to coding your first game. Page 13 -

Annotated sketch This is an annotated transcript of the Light Dependant Resistor animation sketch to help you understand the functions of the different lines of. When you put // before text in, it means it is to be ignored. //this includes the gamer library #include <Gamer.h> //we are going to call the Gamer library :gamer Gamer gamer; int currentframe; //paste your animation frames here This will contain your arrays. Copied from AnimGen //this initates all the functions of the gamer void setup() { gamer.begin(); Serial.begin(9600); //opens up a connection with the serial port at the speed of 9600 void loop() { currentframe = map(gamer.ldrvalue(), 40, 800, 0, NUMFRAMES); //This swaps light readings for animation frame numbers, starting with 40, a low light reading and going up to 800, a very high light reading. This will be mapped across to frames numbers 0, to however many frames your animation has declared. gamer.printimage(frames[currentframe]); //This tells the Gamer to display the frame on the LED matrix Serial.println(gamer.ldrValue()); //This outputs the light reading to the serial monitor every 10 milliseconds, this is not used in the animation, but just lets us see the output of the LDR. delay(10); Page 14 -