warning: Creating default object from empty value in /home/dr_rick/onearmedman.com/modules/taxonomy/taxonomy.pages.inc on line 33.

interactive

Tutorial 2: Digital Read and Write

Knight LightsKnight LightsNow let's put some of this stuff together into a new circuit. You'll need four LEDs, four 220 ohm or 470 ohm resistors, one 1K ohm resistor, a push button, and a bunch of wires.

Hook four wires into the Arduino's digital outputs (check the code to see which ones.) Connect the smaller resistors to each of those wires, then connect an LED to each resistor with its short leg to ground. Be sure to hook up the 5V and GND lines between your Arduino and breadboard.

Knight Lights

Knight Lights

Other Cool Stuff

  • Math
    • max, min, contrain, randomSeed, random
  • Time
    • delay
      • important for adding pauses

Tutorial 1: Data and Serial

Arduino Hooked UpArduino Hooked UpNow we'll run the knight_rider_1 tutorial. Open up the files in the zip archive. All you need for this is to plug in the Arduino to your computer.

Once the board is plugged in, hit reset on the board, then click the Upload to I/O icon on the Arduino interface. Once that's done, click the Serial Monitor icon to see the numbers move up and down. Now you're talking (to the Arduino!)

Arduino Hooked Up

Arduino Hooked Up

Digital Read/Write

  • pinMode
    • takes the pin to be determined
    • takes the mode -> in or out
    • MUST do this for most pins. Forgetting this will get you in trouble

Control structures

  • if/else
    • simple branching
  • switch case
    • more complicate branching
    • for multiple cases

Data Types

  • numbers
    • byte 0 - 255
      • space saving! use this when possible!
    • int
      • handy for negative numbers and most other uses bigger than a byte

Intro

  • Voltage and Logic
  • Digital "Voltage"
    • LOW is 0V
    • HIGH is 5V

Arduino Coding Session

Today, we will run through the basics of Arduino programming. To follow along, please go to the reference section of the Arduino site and step through the functions as we go.

Also, download the files below. They are the Arduino code examples we'll follow once we start making real circuits.

Copyright Mike Edwards 2006-2009. All content available under the Creative Commons Attribution ShareAlike license, unless otherwise noted.

Syndicate content