Where skillset meets mindset.

  • Home
  • Projects
    • Project Summaries
    • Planning
  • Students
    • A High Tech High Student
    • Featurettes
  • Sponsorship & Donations
  • General Resources
    • Shop Tools
      • Hand Tools
      • Power Tools
      • Tool Safety
    • Radio Control Hobbies
    • Laser Cutting
    • Automata
    • Gears & Mechanisms
    • Machining
    • Physics Resources
    • Stained Glass
    • Tips & Guides
    • Electronics
      • Paper Circuits
      • General Electronics
      • Arduino Hardware
    • Coding
      • Processing
      • Arduino
      • Google Apps Script
      • Troubleshooting
  • Educator Resources
    • Project Design Guide
    • Musings
    • Project Ideas
  • GRITLab
    • General
    • Adversity by Design
    • GRITLab Media
    • GRIT Case Study
    • GRITLab Expansion Plan
  • MAKESafe
  • About
    • Scott Swaaley
    • HTH Cover Letter
    • Professional Resume
    • Professional Projects

Arduino Code Examples

Arduino Notes

Although most of this code is universal, it is intended for use on Arduino Uno R3. And remember, the official reference is always the best and most accurate resource.

Other great resources:

  • BlocklyDuino
  • 123d Circuit & Arduino Emulator

Anatomy of a Sketch

Anatomy of a Function

Function Vocab:

  • Function – A logical block of code that has a name and can be executed from somewhere else in the program. The function may do something, or it may return something. (more info)
  • Return – If a function returns something, then it outputs a value.
  • Return Type – Defines what type of variable the function returns. If it returns nothing, then you put “void”.
  • Function Name – Every function needs a unique name. The name should be in camelCase (i.e. “My Function” should be written as “myFunction”).
  • Arguments – Sometimes it’s useful to send information to a program. This can be done as arguments.

Anatomy of a Sketch - New Page (2)

Comments

Comments are a way for a programmer to annotate their code.


Working w/ Variables

Variables are how programmers store, hold, and manipulate date.

Anatomy of Syntax - Variable Declaration (1)

If/Then/Else

Loops & Iteration

Here are some examples of different ways we could make a program count for us using loops.

Conditionals

Tools like if/then/else, while, and for depend on using conditionals. A conditional is an expression that outputs true or false.

Comparison Operators

  • == (equal to)
  • != (not equal to)
  • < (less than)
  • > (greater than)
  • <= (less than or equal to)
  • >= (greater than or equal to)
Boolean Operators

  • && (and)
  • || (or)
  • ! (not)

An Example – serial_repeater

This is an example is called serial_repater and is provided with the MySerial Library.

Blank Flowchart - New Page

Installing Libraries Off Network (Personal Laptop or at Home)

  1. Download the appropriate library as a .zip file (go to File > Download). Libraries are posted here.
  2. Open it to view the contents. It should contain a folder.
  3. Move (or copy and paste) the folder to this exact directory: \My Documents\Arduino\libraries
  4. If it asks, choose to replace the existing folder.

Installing Libraries On Network (at school)

  1. Open the Arduino application.
  2. Navigate to File > Preferences
  3. Set the Sketchbook Location as: T:\Swaaley-Strong\Arduino
  4. Close then re-open the Arduino Application

Using Libraries & Library Examples

  1. When in the Arduino IDE, click Sketch > Import Library.
  2. To find an example of a sketch that uses this library, click File > Examples
Print Friendly, PDF & Email
  • About GRITLab
  • Contact

Copyright © 2021 · Altitude Pro Theme on Genesis Framework · WordPress · Log in