Arduino Reference page
setup()
--the first of the two main parts of any Arduino program.
--determines the state of the digital pins 2-13 i.e. OUPUT
--or INPUT. Also the data rate to the Serial Monitor needs
--to be set here. Example:
setup()
{
pinMode (13, OUTPUT); //pin 13 set as output
Serial.begin(9600); //data rate to SM is 9600 baud
}
loop()
--the second of the two main parts to any Arduino program.
--this is where the working part of the program is written.
--any functions called within loop() are written AFTER the
--loop() part of the program
--Any code here is endlessly repeated as long as there is power
--to the Arduino board to which it is uploaded
// loop checks the button pin each time,
// and will send serial if it is pressed
void loop()
{
if (digitalRead(buttonPin) == HIGH)
serialWrite('H');
else
serialWrite('L');
delay(1000);
}
analogRead()
Description
Reads the value from the specified analog pin.
The ArduinoMega board contains a 16 channel 10-bit analog to digital converter.
This means that it will map input voltages between 0 and 5 volts
into integer values between 0 and 1023.
This yields a resolution between readings of: 5 volts / 1024 units or,
0.0049 volts (4.9 mV) per unit.
The input range and resolution can be changed using analogReference().
It takes about 100 microseconds (0.0001 s) to read an analog input,
so the maximum reading rate is about 10,000 times a second.
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()
Description: Prints data to the serial port as human-readable ASCII text.
his command can take many forms.
Numbers are printed using an ASCII character for each digit.
Floats are similarly printed as ASCII digits, defaulting to two decimal places. Bytes are sent as a single character.
Characters and strings are sent as is.
Syntax
Serial.print(val)
Serial.print(val, format)
Parameters
val: the value to print - any data type
/*Uses a FOR loop for data and prints a number in various formats.
*/
int x = 0; // variable
void setup() {
Serial.begin(9600); // open the serial port at 9600 bps:
}
void loop() {
// print labels
Serial.print("NO FORMAT"); // prints a label
Serial.print("\t"); // prints a tab
Serial.print("DEC");
Serial.print("\t");
Serial.print("HEX");
Serial.print("\t");
for(x=0; x< style="font-weight: bold;">
Serial.println()Description
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').
This command takes the same forms as Serial.print().Syntax
Serial.println(val)
Serial.println(val, format)Serial.println(x, BYTE); // prints x as a raw byte value,
//then adds the carriage return with "println"
I'll get a 'round tuit' some time soon..
ReplyDeleteI'm just going to post different KEYWORDS
ReplyDeletein different places on my blog, but by
clicking on KEYWORDS, you can get them all together