Learning How to Code in Arduino Worksheet 2: Serial.println(), State Variables and Counters

Similar documents
Arduino Lesson 5. The Serial Monitor

Your Multimeter. The Arduino Uno 10/1/2012. Using Your Arduino, Breadboard and Multimeter. EAS 199A Fall Work in teams of two!

Arduino Lesson 14. Servo Motors

Theory and Practice of Tangible User Interfaces. Thursday Week 2: Digital Input and Output. week. Digital Input and Output. RGB LEDs fade with PWM

Excel 2007: Basics Learning Guide

DS1307 Real Time Clock Breakout Board Kit

Arduino Lab 1 - The Voltage Divider

All the examples in this worksheet and all the answers to questions are available as answer sheets or videos.

UDG1000 Hach PCX2200 Serial Port Input Driver configuration

PHYS 2P32 Project: MIDI for Arduino/ 8 Note Keyboard

Lab 3 - DC Circuits and Ohm s Law

ARDUINO SEVERINO SERIAL SINGLE SIDED VERSION 3 S3v3 (REVISION 2) USER MANUAL

Numerator Denominator

Activity 6 Graphing Linear Equations

Graphing in excel on the Mac

Arduino Lesson 13. DC Motors. Created by Simon Monk

Years after US Student to Teacher Ratio

Arduino Lesson 1. Blink

AirCasting Particle Monitor Bill of Materials

Arduino Wifi shield And reciever. 5V adapter. Connecting wifi module on shield: Make sure the wifi unit is connected the following way on the shield:

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Arduino Lesson 16. Stepper Motors

CHAPTER 11: Flip Flops

Administrator Quick Start Guide

Saitek. SST Programming Software USER GUIDE

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Arduino Lesson 0. Getting Started

A PRACTICAL GUIDE TO db CALCULATIONS

Inside Blackboard Collaborate for Moderators

Lab 6 Introduction to Serial and Wireless Communication

Decimals and other fractions

This explains why the mixed number equivalent to 7/3 is 2 + 1/3, also written 2

Fractions. If the top and bottom numbers of a fraction are the same then you have a whole one.

DSL Self-install Kit Instructions

Creating a Database using Access 2007

PRODUCTIVITY THROUGH INNOVATION 600 CONTROL DIRECT DRIVE TECHNICAL/OPERATION MANUAL

MANUAL FOR RX700 LR and NR

2.2" TFT Display. Created by Ladyada. Last updated on :15:09 PM EDT

Tutorials Drawing a 555 timer circuit

Exponents. Exponents tell us how many times to multiply a base number by itself.

Lab 2: Resistance, Current, and Voltage

mdm-mp3 minidirector with MP3 Player

Calculator Worksheet--page 1

Numeracy Preparation Guide. for the. VETASSESS Test for Certificate IV in Nursing (Enrolled / Division 2 Nursing) course

Connecting Arduino to Processing a

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL

DSD For Windows Basic Setup Instructions

Measuring Resistance Using Digital I/O

Series and Parallel Resistive Circuits Physics Lab VIII

First Bytes Programming Lab 2

Computer Skills Microsoft Excel Creating Pie & Column Charts

CM HOST CM CardTransporter Fuel Communication and Management Software Software version up to 3.1

Using Microsoft Project 2000

Advanced Programming with LEGO NXT MindStorms

OVERVIEW Playbacks: Shortcuts: Memories: Data Entry Wheels: Touchpad: Master and Blackout:

RS-232 Communications Using BobCAD-CAM. RS-232 Introduction

1 Coffee cooling : Part B : automated data acquisition

ECEN 1400, Introduction to Analog and Digital Electronics

TouchKit Software User manual for Windows 7 Version:

How do you use word processing software (MS Word)?

An Introduction to Box.com

Excel 2003 A Beginners Guide

Common Multiples. List the multiples of 3. The multiples of 3 are 3 1, 3 2, 3 3, 3 4,...

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

HOW TO GET A SOIL MAP FROM THE WEB SOIL SURVEY

Application/Connection Examples

Fractions. Chapter Understanding fractions

Uniden s E-Scanner Programming Software Version 2.0

Excel 2007 A Beginners Guide

Virtual Heart User Manual Username Password

Using VLOOKUP to Combine Data in Microsoft Excel

Lecture 2 Mathcad Basics

Set up and Blink - Simulink with Arduino

User Manual. AS-Interface Programmer

The Center for Teaching, Learning, & Technology

Using Microsoft Visual Studio API Reference

ConnectWise PSA Integration Guide

Introduction to Arduino

Bluetooth + USB 16 Servo Controller [RKI-1005 & RKI-1205]

Jianjian Song LogicWorks 4 Tutorials (5/15/03) Page 1 of 14

P C B Wiz a r d 3 T u t o r i a l 3 Drawing a test probe circuit

IR Communication a learn.sparkfun.com tutorial

Appointments: Calendar Window

FRACTIONS OPERATIONS

VHDL Test Bench Tutorial

ETHERNET WEATHER STATION CONNECTIONS Application Note 33

Select Correct USB Driver

THRUST CURVE LOGGER V-4.200

NF5-12 Flexibility with Equivalent Fractions and Pages

Doing Multiple Regression with SPSS. In this case, we are interested in the Analyze options so we choose that menu. If gives us a number of choices:

The goal is to program the PLC and HMI to count with the following behaviors:

Resistors in Series and Parallel Circuits

Lab 4 - Data Acquisition

EXCEED IEP Goals Product Screen

Solving the Rubik's Revenge (4x4x4) Home Pre-Solution Stuff Step 1 Step 2 Step 3 Solution Moves Lists

1. Three-Color Light. Introduction to Three-Color Light. Chapter 1. Adding Color Pigments. Difference Between Pigments and Light. Adding Color Light

Greetings Keyboard Mastery Keyboarding Students! Teacher: Mrs. Wright

Transcription:

Learning How to Code in Arduino Worksheet 2: Serial.println(), State Variables and Counters Jason Krugman Physical Computing - Fall 22 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// How to Use the Serial.print() command Serial.print() allows us to debug our programs, aka, figure out what is going on To use Serial.print(), we need to include the following piece of code in the setup: This line of code tells the Arduino to start sending data back to the computer through the USB port. The 96 part is the BAUD rate the number of pulses per second that the Arduino should send out to the computer. For our purposes this will always be 96. If we set up a button circuit like the one from ITP s Digital In/ Digital Out Lab (shown below), we can start experimenting with Serial.print(); and Serial.println(); (when you add the ln at the end of Serial.print it skips a line when printing out) http://itp.nyu.edu/physcomp/labs/digitalinout%2%2 For the resistor, it does not have to be exactly the one shown. Anything greater than K ohm is fine. basically any resistor that has an orange or greater stripe next to the gold. Remember ROYGBIV? Resistor values increase by a power of as the stripe next to the gold moves to the right in ROYGBIV or R < O < Y < G < B < I < V < is the simple for greater than less than. It s a hungry mouth and wants to eat whichever number is bigger. Black is smallest, then brown, then R, then O, and so an so forth.

If we set up the circuit above and upload the code below to our Arduino, it will print out a value for the buttonval variable every time When we upload the program to the Arduino, run it, and then open the Serial monitor (click on the little magnifying glass in the upper right hand corner of the Arduino window), we would see something like this in the black display in the bottom of the Arduino window. And when we press the button down that we have set up on the breadboard, we would see: The Arduino will keep printing out the buttonval variable every milliseconds. We put the delay in there to slow things down a little so that we can read it.

We could also do something like this: This would print out: buttonval is buttonval is buttonval is buttonval is buttonval is buttonval is buttonval is buttonval is or buttonval is Notice the use of quotes and also that I used both Serial.print() and Serial.println().

What is a state variable? A state variable is used to remember what state something is in, or was in, at a certain point in time. State variables are great for creating a series of conditions that have to be satisfied in order for another event to take place. For example, to make a simple combination lock, we could include two buttons. If we wanted the lock to open when both buttons are pushed at once, we could write something like: Do you see the mistake that I made when I wrote up this code? Its very small but it will cause an error when the code runs. We can also write the if statements another way using the AND operator which we write as && This means that both things inside the if statement condition have to be true in order for the event to take place (the event being that we print out the secret code). Another very useful way to write if statement conditions is with the OR operator which we write

Those symbols are pipes, not capital i s. They look the same but they re not. Its on the same key as the \ If we were to write, then if either buttonone OR buttontwo are, the secret code would be printed. Remember Venn Diagrams (those overlapping circles with mutual or exclusive areas)? It s the same thing. Okay, here is where state variables come in What if both buttons must be pressed but not at the same time? To do this we would need two variables to keep track of if each button has been pressed up to the current point in time. The below code does this with two additional variables, one for each button.

What is a counter? A counter is a variable that we use to. count. We do this by adding or subtracting to it every time we do something. We can also use division and multiplication with counters, but for now we will stick with addition. If we want program LED blinks every so often, we could write a program that looks like this: Lets talk a bit about what this program is doing. First of all, what is counter ++? This notation means that counter will add to its current value every time it encounters this command. -- works the same way ++ does except it takes away. You can also do something similar to this with += or -=. For example, counter += 5; will add 5 to the value of counter each time we run that line. Its the same as writing this: counter = counter + 5; Just a shortcut. We can also do the same with / or * (which is the symbol for multiply). What happens if we do counter**? I don't know, haven't tried it. We could use the Serial.print() command to see what the value of that would be. To review, these are all the same thing: counter++; counter = counter + ; counter +=;