Thursday, May 6, 2010

Arduino Key Works (Task 25, 33)

setup(): This is a loop that only runs once when the arduino is first powered on (or reset). In this loop settings like pinMode() are specified and variables are set/reset.

loop(): This is where the main portion of the program is. This is a constant loop that begins again immediately after finishing.

analogRead(): This is used to pull values from the analogue pins. The pin number goes in the brackets (analogRead(2)). This is mostly done with sensors that can have a wide range of values (usually based off resistance e.g. LDR, Temperature sensor). The value read is always between 0 and 1023 depending on resistance.

Serial.print(): This is to write what ever is in the brackets out to a serial monitor. Variables can simply be typed in i.e. Serial.print(count) but if you wish to write out simple text it must be within quotation marks i.e. Serial.print("Text Here"). Anything in the brackets will be added to the previous line (unless the previous line was written with Serial.println()).

Serial.println(): Same as above except the message sent will end the current line.

pinMode(): This is used to set whether a digital pin is an input or an output (pinMode(13,INPUT) sets pin 13 as a digital input where as pinMode(13,OUTPUT) is the opposite). This is typically only used in setup() but can also be used in the main loop().

digitalRead(): This is used to check a sensor or button on a digital pin. This will either return HIGH or LOW. An example of how digital read is used: state = digitalRead(13).

No comments:

Post a Comment