setup() - Used to initialised varibles as the start of a program eg pinMode(buttonPin, INPUT);
loop() - Loops anything you state on the board eg void loop()
{
if (digitalRead(buttonPin) == HIGH)
serialWrite('H');
else
serialWrite('L');
delay(1000);
}
digitalWrite - DigitalWrite is used to output something such as an LED as HIGH (on) or LOW (off) eg digitalWrite(ledPin, HIGH);
analogRead()- Reads the value from the specified analog pin eg int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V
int val = 0; // variable to store the value read
void setup()
{
Serial.begin(9600); // setup serial
}
void loop()
{
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
}
Serial.print()- Prints data to the serial port as human-readable ASCII text. eg •Serial.print("Hello world.") gives "Hello world."
Serial.println()- Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). eg Serial.println("Hello world.") followed by a new line
pinMode()- Configures the specified pin to behave either as an input or an output. eg pinMode(ledPin, OUTPUT); // sets the digital pin as output
digitalRead() - Reads the value from a specified digital pin, either HIGH or LOW. eg
int ledPin = 13; // LED connected to digital pin 13
int inPin = 7; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(inPin, INPUT); // sets the digital pin 7 as input
}
void loop()
{
val = digitalRead(inPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the button's value
}
Thursday, March 4, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment