Learn Arduino with Olympia Circuits
Learn Arduino
  • Home
    • Get Started
    • How to Use This Site
  • Electronics
    • The Basics
    • Electricity Flows like Water
    • Electronic Components
    • The Arno Board
  • Programming
    • The Basics
    • setup and loop Blocks
    • Variables and Arrays
    • Connecting with the Pins
    • Flow Control >
      • if Statement
      • Loops
      • Delays
    • Functions
    • Serial Communication
    • USB
    • Some Thoughts
  • Projects
    • Projects 1 >
      • 1.01: Blink
      • 1.02 Blink x2
      • 1.03 Blink Faster
      • 1.04 LED Chase!
      • 1.05 Wait To Blink
      • 1.06 Blink a Little Faster Now
      • 1.07 LED Fade
      • 1.08 RGB Blink
      • 1.09 Change RGB Color with SW1
      • 1.10 Fade RGB Colors
      • 1.11 Reaction Time Game
    • Projects 2 >
      • 2.01 Hello World
      • 2.02 Talk Back
      • 2.03 ASCII Values
      • 2.04 Ski Game
      • 2.05 Demonstration of the String Object
    • Projects 3 >
      • 3.01 Read the Potentiometer
      • 3.02 ASCIIbet Soup
      • 3.03 Potentiometer sets LED Brightness
      • 3.04 Potentiometer Sets Blink Rate
      • 3.05 LED Chase, Part II
    • Projects 4 >
      • 4.01 Bringing the Piezo to Life
      • 4.02 Controlling the Piezo with a Function
      • 4.03 Piezo C Major
      • 4.04 Piezo Greensleaves
      • 4.05 Piezo Metronome
      • 4.06 Piezo as an Input
      • 4.07 Piezo as an Input 2
      • 4.08 Metronome II
      • 4.09 Piezo Playback
      • 4.10 Piezo Fireworks
      • 4.11 Piezo Mosquito
    • Projects 5 >
      • 5.01 The Phototransistor
      • 5.02 Light and Sound
      • 5.03 Light and Sound II
    • Projects 6 >
      • 6.01 EEPROM
      • 6.02 I2C Address Scan
      • 6.03 Read the I2C Temperature Sensor
      • 6.04 High Temperature Alarm
    • Projects 7 >
      • 7.01 Arno Phone Home
      • 7.02 Keyboard Alphabet
      • 7.03 Move Mouse
      • 7.04 Draw Squares
    • Special Projects >
      • Bike Light Demo
  • References
    • Arno Pin Key
    • Arno Schematic
    • Project Index

programming: some thoughts...

Programming is a lot of fun once you get the hang of it.  It’s like solving a puzzle.  You start with an idea, a goal, or a problem that you’re trying to solve.  You start by breaking the problem down into manageable pieces: how do I collect the information that I need?  Which decisions am I going to make based on the information?  What are my outputs?  Then you translate these ideas into your computer language (Arduino in this case), making sure to follow all of its rules. Then you test your program and make improvements.  It’s a great feeling to be able to start with an idea and then bring it to life through programming.

It’s important to do things step by step and make sure your code works along the way.  For example, you might write a program that takes a reading from a sensor and then controls a motor.  If you write the entire program, test it, and it doesn’t work you’re left wondering “is the problem with the sensor, the motor, or my program?”  It makes more sense to write the code for the sensor first and then output the results to the serial monitor.  Once this works and the results make sense, you can move on to the motor.  With the motor, you might start with “hard coded” values to control it.  For example, if the motor is supposed to turn forward when the value of the variable sensorOutput is > 10 and backwards when it is < 0, you can just include the line sensorOutput = 12 and see what the motor does.  Then you can see what the motor does when you change the line to sensorOutput = -2.   Once you’re sure each part of the program works on its own, you can focus on combining them. 

Programming languages can seem rigid with their need for exact syntax and structure.  But as long as you follow the rules, you’re free to do anything you want.  There’s tons of room for creativity.  If you can piece together a logical sequence of steps to solve a problem and put it into the right syntax, then it will probably work.  If it doesn’t then you need to go back and check your syntax and rethink you’re logic.  Invariably, you’re going to learn something from the experience.  There’s almost always more than one way to do the same task.  As you become more skilled, you’ll be able to accomplish more tasks with fewer lines of code.  You’ll find shortcuts and learn to write flexible, reusable code that will work in different situations. 

next: projects

Copyright Olympia Circuits LLC 2014. All Rights Reserved.