1. There are many ways to write one given algorithm\n2. An algorithm requires certain assumptions\n3. An algorithm includes decision making\n4. A complex algorithm should be broken down into modular pieces.\n
The computer needs to know what type of data you&#x2019;re going to be storing, so it knows how much memory to set aside. ints take up less room than floats. \n
If you forget, check the reference on the website.\n
Our methods so far:This circuit is a “one-liner”Not many possibilities for interactionCircuits hard-wired for specific purposesMaking changes requires you to re-wire, snip, de-solder, etc...
What is a “microcontroller” ?•A small, inexpensive computer. Less sophisticated than your mac... think calculator•Good for taking INPUT data, processing it, OUTPUTTING something.•Route several different inputs to outputs, one input to many outputs, etc...•Many electronic devices with any “smarts” whatsoever have some microcontroller.•Higher level vs. Lower lever (Arduino is mid) Wiring Gainer BX 24 PIC micro
Where does themicrocontroller fit in?As an input...Count button clicksSense pressureMultiple switchesHow long switch is held down
As an output...Automate the lightsAnimate multiple lights in a sequence
Arduino-A “single board” microcontroller and a software suite for programming it.-Programming language is based on WIRING (similar to C++) -IDE is based on PROCESSING, so it looks friendly.-An Italian production (IVREA Institute)-USB to Serial interface. I/O pins. Accepts shields and components easily. Inexpensive & open-source-Loaded with Atmel AVR microcontroller chips. Preinstalled “bootloader” makes it easy to program right out of the box!-Clones exist.
Anatomy of an Uno- 28 pin IC (brain). ATmega168, 328 or similar.- A variety of components, LEDs, a crystal oscillator, a 5V regulator, etc.- FTDI chip that converts USB to Serial for easy communication with your pute.- 14 Digital I/O pins. (0-13)- 6 Analog In pins (0-5)- 6 pins can be used as Analog Out (3,5,6,9,10,11)
DIGITAL I/O PINS USB 5VREGULATOR MICROCONTROLLEREXTERNAL POWER POWER ANALOG IN
Each DIGITAL OUT pin acts like a mini 5V power supply.Don’t forget about Ground! + 9V 470 instead of...
Now we need to give the board instructions on what to do...
What is Code?A set of instructions (“an algorithm”)that tells the board exactly what to do,for how long and in what order. Aprocedure, a program.Knitting a scarf:Row 1: (RS) *K2, P2* acrossRows 2, 3 & 4: Repeat Row 1Row 5: (RS0 *K2, P2, C8F* Repeat to last 4 sts, K2, P2Row 6: Repeat Row 1Repeat rows 1-6 for desired length, ending with row 4Bind off in K2, P2 pattern
Hiking directions to Point BreakFrom the North:-Follow the trail from the Nature Center-Turn right at the Water Tower, walk up to the Old Oak Tree-Follow directions from the Old Oak Tree.From the South:-From the hPicnic Grove, follow the Botany Trail-Turn right on the South Meadow Trail-Turn right on the Meadow Ranch Trail, walk until you see the OldOak Tree-Follow directions from the Old Oak Tree.From the Old Oak Tree:-Follow the path under the tree-Turn right onto the Long Hill Trail-Follow the trail until you reach Point Break
A code snippet from PROCESSING Produces This:* Arduino is based off ofsimilar. Don’t IDE. So they look very Processing’s mix the two up though.
Anatomy of anArduino ProgramButtons for common tasks Comments Variables Setup & Loop Functions Message Area Console
Structure Up Top: “Declare” and “Assign” any variables you’re going to be using. SETUP: The code in this block runs only once when the program begins. LOOP: The code in this block runs after the setup, 100’s of times a second. Each line of code runs once from top to bottom.Once the loops is entered, we stay there until the Arduino is unplugged.
Breakdown Make a few notes to myself, so when Ireturn to this later, I can remember more easily... Give the #13 a nickname so I can use itmultiple times. If I change 13 to 10 now, I only have to change it once, here!Make sure Arduino knows pin 13 (nicknamed “led”) is going to serve as OUTPUT.Specify some instructions for how long to turn the LED on/off. This part will repeat over and over again.If you remove the last delay(1000); what happens? Can you make the LED blink “SOS”?
A few definitions Variable: Store a value (integer, decimal number, true/false value, etc.) in computer memory so you can use it many times throughout the life of the program. Variables have two steps: declare and assign. Sometimes these happen on one line, like you see below. So this: Declare that that Assign it a value of you’re making a 13, representing the variable called pin that the LED is “led” of type int. connected to! Is identical to this:... gets assigned to what’s on the left. = What’s on the right hand side of the As far as the Arduino equals sign... is concerned.
A few definitionsFunction: Code modules that can be “called” in your program. A function is actuallya ‘nickname’ given to other lines of code, written and stored elsewhere. Arduino hasa large selection of existing functions. Each one does something specific like “send5v to pin X” or “delay for one second”. Functions can be customized sometimes, with“parameters” You can write your own functions too! These are just the ones that come digitalWrite takes with Arduino. the name of the two parameters, function begin which pin? and what called. Note the () state? It’s like saying “set ‘led’ (13) to HIGH”. Meaning... “Send 5V to pin 13”
For more, visit the Arduino website:arduino.ccand check out their tutorials:http://arduino.cc/en/Tutorial/Foundations