Arduino study notes (c) - Program Structure

1, the basic installation and use the IDE

1.1 Installation

  Arduino using the Arduino IDE development, IDE is easy to install, download page  after the official download site to install it yourself

1.2 Project example

  To open an existing project example, select File → Example → Basics → Blink. 

 

 

1.3 Select Arduino board.

  Go to the Tools → Board, and then select your board.

 

 

 1.4 Select the serial port

 

 

 1.5 burning program

 

 

 

  A  - used to check whether there are any compilation errors.

  B  - for program upload Arduino board.

  C  - used to create a shortcut to a new sketch.

  D  - for example one directly open sketch.

  E  - to save the sketch.

  F.  - means for receiving serial data and transmits serial data to the serial monitor plate from the plate.

 

  Now, just click environment "Upload" button. Wait a few seconds, you will see the RX and TX LED panel lights flashing. If the upload is successful, the status bar "Done uploading" message is displayed.

2, Arduino program structure

2.1 Structure

  Software architecture consists of two main functions:

    Setup () function

    Loop () function

  

 

 

 

Void setup ( ) {

}
  • PURPOSE - will be called when the sketch starts  setup () function. Use it to initialize variables, pin mode, enabled libraries. The setup function can only run once after each power up or reset the Arduino board.

  • INPUT - -

  • OUTPUT - -

  • RETURN- -

Void Loop ( ) {

}
  • PURPOSE- 在创建了用于初始化并设置初始值的setup()函数后,loop() 函数,正如它的名称所指,允许你的程序连续循环的更改和响应。可以使用它来主动控制Arduino板。

  • INPUT - -

  • OUTPUT - -

  • RETURN- -

 

3、Arduino数据类型

3.1 所有数据类型

void Boolean char Unsigned char byte int Unsigned int word
long Unsigned long short float double array String-char array String-object

void

  void关键字仅用于函数声明。它表示该函数预计不会向调用它的函数返回任何信息。

Boolean

  布尔值保存两个值之一,true或false。每个布尔变量占用一个字节的内存。

Char

  一种数据类型,占用一个字节的内存,存储一个字符值。字符文字用单引号写成:'A',对于多个字符,字符串使用双引号:"ABC"。

  但是,字符是存储为数字。你可以在ASCII图表中查看特定编码。这意味着可以对使用ASCII值的字符进行算术运算。例如,'A'+1的值为66,因为大写字母A的ASCII值为65。

unsigned char

  unsigned char是一种无符号数据类型,占用一个字节的内存。unsigned char数据类型编码数字为0到255。

byte

  一个字节存储一个8位无符号数,从0到255。

int

  整数(int)是数字存储的主要数据类型。int存储16位(2字节)值。这产生-32768至32767的范围(最小值为-2^15,最大值为(2^15)-1)。

  int的大小因板而异。例如,在Arduino Due中,int存储32位(4字节)值。这产生-2147483648至2147483647的范围(最小值-2^31和最大值(2^31)-1)。

Unsigned int

  unsigned int(无符号整数)与int相同,存储2字节。然而,它们只存储正值,产生0到65535(2^16)-1的有效范围。Due存储4字节(32位)值,范围从0到4294967295(2^32-1)。

Word

  在Uno和其他基于ATMEGA的板上,一个word存储一个16位无符号数。在Due和Zero上,它存储一个32位无符号数。

Long

  Long变量是用于数字存储的扩展大小变量,存储32位(4字节),从-2147483648到2147483647。

unsigned long

  unsigned long变量是用于数字存储的扩展大小变量,并存储32位(4字节)。与标准的long不同,unsigned long不会存储负数,它们的范围为0到4294967295(2^32-1)。

short

  short是16位数据类型。在所有Arduinos(基于ATMega和ARM)上,一个short存储一个16位(2字节)值。这产生-32768至32767的范围(最小值为-2^15,最大值为(2^15)-1)。

float

  浮点数的数据类型是具有小数点的数字。浮点数通常用于近似模拟值和连续值,因为它们的分辨率高于整数。

  浮点数可以大到3.4028235E+38,也可以低到-3.4028235E+38。它们被存储为32位(4字节)信息。

double

  在Uno和其他基于ATMEGA的板上,双精度浮点数占用四个字节。也就是说,double实现与float完全相同,精度没有增益。在Arduino Due上,double具有8字节(64位)精度。

4、变量和常亮

与其他编程语言逻辑及风格基本相同

变量按作用范围分为局部变量和全局变量,此处略去不讲

5、运算符

运算符类型

  • Arithmetic Operators 算术运算符
  • Comparison Operators 比较运算符
  • Boolean Operators 布尔运算符
  • Bitwise Operators 位运算符
  • Compound Operators 复合运算符

算术运算符

=

+

-

*

/

%

比较运算符

==

!=

<

>

<=

>=

布尔运算

&&

||

位运算符

Guess you like

Origin www.cnblogs.com/luxd/p/12205173.html
Recommended