Arduino programming Language Manual (Simple version)

Source: Internet
Author: User
Tags mathematical functions min processing text switch case

Taobao Shop: http://robotstudio.taobao.com group number: 259189548

Arduino language Annotations The Arduino language is based on C + +, in fact, the basic C language, the Arduino language is only the AVR microcontroller (microcontroller) related to some parameter settings are functional, do not need us to understand his bottom, Let us not understand the AVR microcontroller (microcontroller) friends can also easily get started.
In the time of contact with the Arduino DIYer, found that some friends of the Arduino language is still relatively difficult to start, then here I would simply comment on the Arduino language (I am also half a jar of water, the wrong place also ask you to correct).

Key words:
If
If...else
For
Switch case
While
Do ... while
Break
Continue
Return
Goto
Syntax symbols:
;
{}
//

Operator:
=
+
-
*
/
%
==
!=
<
>
<=
>=
&&
||
!
++
--
+=
-=
*=
/=
Data type:
Boolean Boolean type
Char
byte byte type
Int
unsigned int
Long
unsigned long
Float
Double
String
Array
void
Data type conversions:
CHAR ()
BYTE ()
Int ()
Long ()
Float ()
Constant:
High | Low indicates the level of the digital IO port, high (1), and lower (0).
INPUT | Output represents the direction of the digital IO port, input represents the inputs (high-impedance state), and output indicates the outputs (the AVR can provide 5 V voltage 40mA current).
true | False true indicates true (1), False indicates false (0).

The above is the basic C language of the key words and symbols, C language based on all should understand its meaning, there is no too much explanation.

Structure
void Setup () initialize variable, PIN mode, call library function, etc.
void loop () continuous execution of statements within functions
Function
Digital I/O

The Pinmode (PIN, mode) digital IO port input and output mode defines the function, the PIN is represented as 0~13, and mode is expressed as input or output.
Digitalwrite (PIN, value) the output level of the digital IO port defines the function, and the PIN is expressed as 0~13,value as high or low. For example, define high to drive LEDs.
the int digitalread (PIN) digital IO port reads the input level function, and the PIN is expressed as 0~13,value as high or low. For example, a digital sensor can be read.
Analog I/O

the int analogread (PIN) simulates the IO port read function, and the PIN is represented as 0~5 (Arduino Diecimila is 0~5,arduino nano for 0~7). For example, the analog sensor can be read (10-bit ad,0~5v is represented as 0~1023).
Analogwrite (PIN, value)-PWM digital IO port PWM output function, Arduino digital IO port labeled PWM IO port can use this function, PIN represents 3, 5, 6, 9, ten, 11,value expressed as 0~255. For example, it can be used for motor PWM speed regulation or music playback.
Extended I/O

Shiftout (Datapin, Clockpin, Bitorder, value) SPI external IO extension functions, usually using a 74hc595 with SPI interface to do 8 IO expansion, Datapin for the data port, Clockpin for the clock port, Bitorder is the direction of data transmission (Msbfirst high in front, Lsbfirst low in front), value represents the data to be transmitted (0~255), in addition to an IO port to do 74hc595 enable control.
unsigned long Pulsein (PIN, value) The Pulse length record function, which returns the time parameter (US), which is indicated as 0~13,value as high or low. For example, if value is high, then when the pin input is higher, the timer starts, and when the pin input is low, the timer is stopped, and then the time is returned.
Time function

unsigned long Millis () returns the time function (in MS), which means that it takes about 50 days for a program to start timing and return a record's parameters when it runs.
Delay (ms) latency function (unit ms).
Delaymicroseconds (US) delay function (US).
Mathematical functions

Min (x, y) to find the minimum value
Max (x, y) to find the maximum value
ABS (x) calculates absolute value
Constrain (x, a, b) constraint function, lower bound A, upper b,x must be between AB to return.
The map (value, Fromlow, Fromhigh, Tolow, Tohigh) constraint function, value must be between Fromlow and Tolow and between Fromhigh and Tohigh.
Pow (base, exponent) the root function, base of the exponent-square.
Sq (x) squared
sqrt (x) Open radical
Trigonometric function

Sin (RAD)
Cos (RAD)
Tan (RAD)
Random number function

The Randomseed (seed) random number port defines the function, and seed represents the read analog port Analogread (PIN) function.
The long random number function, which returns data greater than or equal to 0, is less than Max.
The long random number function, which returns data greater than or equal to Min, is less than Max.
External interrupt function

Attachinterrupt (interrupt,, mode) external interrupts can only be used to digital IO Port 2 and 3,interrupt represents the initial interrupt port 0 or 1, indicating a function function, Mode:low low interrupt, change changes on the interrupt, Rising rising edge interrupted, falling falling edge interrupted.
Detachinterrupt (interrupt) interrupt switch, interrupt=1 Open, interrupt=0 off.
Interrupt Enable function

Interrupts () Enable interrupt
Nointerrupts () No interruption
Serial transceiver function

Serial.begin (speed) serial port defines the baud rate function, speed represents the baud rate, such as 9600,19200.
int serial.available () determines the buffer state.
int Serial.read () reads the serial port and returns the received parameter.
Serial.flush () empties the buffer.
Serial.print (data) serial port output data.
The SERIAL.PRINTLN (data) serial port outputs data with a carriage return character.

Official Library files
Eeprom-eeprom Read-Write library
Ethernet-Ethernet Controller Program Library
LIQUIDCRYSTAL-LCD Control Program Library
Servo-Rudder Control Program Library
Softwareserial-Any digital IO port analog serial Port program library
Stepper-Stepper Motor Control Program Library
WIRE-TWI/I2C Bus Program Library
Matrix-led Matrix Control Program Library
sprite-led Matrix image Processing Control Program Library
Unofficial library file
DATETIME-A Library for keeping track of the current date and time in software.
Debounce-for reading noisy digital inputs (e.g. from buttons)
Firmata-for communicating with applications in the computer using a standard serial protocol.
Glcd-graphics routines for LCD based on the KS0108 or equivalent chipset.
Lcd-control LCDs (using 8 data lines)
LCD 4 Bit-control LCDs (using 4 data lines)
Ledcontrol-for controlling LED matrices or seven-segment displays with a MAX7221 or MAX7219.
Ledcontrol-an alternative to the Matrix library for driving multiple LEDs with Maxim chips.
Messenger-for processing text-based messages from the computer
Metro-help you time actions at regular intervals
Mstimer2-uses the Timer 2 interrupt to trigger an action every N milliseconds.
Onewire-control devices (from Dallas Semiconductor), the one wire protocol.
Ps2keyboard-read characters from a PS2 keyboard.
Servo-provides software support for Servo motors on any pins.
Servotimer1-provides hardware support for Servo motors on pins 9 and 10
Simple Message system-send messages between Arduino and the computer
Sserial2mobile-send text messages or emails using a cell phone (via AT commands over software serial)
Textstring-handle strings
Tlc5940-16 Channel-bit PWM controller.
X10-sending X10 signals over AC power lines

The above library files need to be downloaded to the compilation environment (directory: arduino-0011\hardware\libraries) to be used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.