11.07.2015 Views

ARDX-experimenters-g.. - Oomlout

ARDX-experimenters-g.. - Oomlout

ARDX-experimenters-g.. - Oomlout

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

03 PROGprogrammingprimer.: A Small Programming Primer:.Arduino Programming in BriefThe Arduino is programmed in the C language. This is a quick little primer targeted at peoplewho have a little bit of programing experience and just need a briefing on the ideosyncrocies ofC and the Arduino IDE. If you find the concepts a bit daunting, don't worry, you can start goingthrough the circuits and pick up most of it along the way. For a more in depth intro theArduino.cc website is a great resource (the foundations page http://tinyurl.com/954pun)StructureEach Arduino program(often called a sketch) hastwo required functions(also called routines).void setup(){ }All the code between the twocurly brackets will be run oncewhen your Arduino programfirst runs.void loop(){ }This function is run after setuphas finished. After it has runonce it will be run again, andagain, until power is removed.SyntaxOne of the slightlyfrustrating elements of C isits formating requirements(this also makes it verypowerful). If you rememberthe following you should bealright.// (single line comment)It is often useful to write notesto yourself as you go alongabout what each line of codedoes. To do this type two backslashes and everything until theend of the line will be ignored byyour program.{ } (curly brackets)Used to define when a block ofcode starts and ends (used infunctions as well as loops)/* */(multi line comment)If you have a lot to say you canspan several lines as acomment. Everything betweenthese two symbols will beignored in your program.; (semicolon)Each line of code must beended with a semicolon (amissing semicolon is often thereason for a programmerefusing to compile)VariablesA program is nothing morethan instructions to movenumbers around in anintelligent way. Variables areused to do the movingboolean (boolean)A simple True or False variable.Useful because it only uses onebit of RAM.04int (integer)The main workhorse, stores anumber in 2 bytes (16 bits).Has no decimal places and willstore a value between -32,768and 32,768.float (float)Used for floating point math(decimals). Takes 4 bytes (32bits) of RAM and has a rangebetween -3.4028235E+38 and3.4028235E+38.long (long)Used when an integer is notlarge enough. Takes 4 bytes(32 bits) of RAM and has arange between -2,147,483,648and 2,147,483,648.char (character)Stores one character using theASCII code (ie 'A' = 65). Usesone byte (8 bits) of RAM. TheArduino handles strings as anarray of char’s

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!