A treasure bought a set a few days ago, and it has no time. Today, I started to learn this "Toy ".
1. variable data type of Arduino:
Data Type
Data Type |
Ram |
Range |
Void keyword |
N/ |
N/ |
Boolean |
1 byte |
0 to 1 (true or false) |
Byte |
1 byte |
0 to 255 |
Char |
1 byte |
-128 to 127 |
Unsigned char |
1 byte |
0 to 255 |
Int |
2 byte |
-32768 to 32767 |
Unsigned int |
2 byte |
0 to 65535 |
Word |
2 byte |
0 to 65535 |
Long |
4 byte |
-2147483648 to 2147483647 |
Unsigned long |
4 byte |
0 to 4294967295 |
Float |
4 byte |
-3.4028235e38 to 3.4028235e38 |
Double |
4 byte |
-3.4028235e38 to 3.4028235e38 |
String |
1 byte + x |
Character array |
Array |
1 byte + x |
Variable set |
2. Simple structure of the Arduino program:
1 Int Tmppin = 8 ;// Pin 2 3 // Initialization settings 4 Void Setup (){ 5 Pinmode (tmppin, input ); 6 } 7 8 // Main Function 9 Void Loop (){ 10 }
Define variables at the beginning. Assign the pin number to a variable.
The setup and loop methods are required by Arduino. Setup is equivalent to initialization (similar to the constructor or init method). Loop is equivalent to the main method, which is the main execution method of Arduino. Unlike other languages, this method is executed repeatedly.
3. Program IO--INPUT and Output
Set I/O in pinmode in setup. There are two types of Arduino: one input source and the other output source. Use the pinmode method to set the effect of pins.
4. digitalread and digitalwrite
1 Int Tmppin1 = 8 ; 2 Int Tmppin2 =9 ; 3 4 Void Setup (){ 5 Pinmode (tmppin1, input ); 6 Pinmode (tmppin2, output ); 7 } 8 9 Void Loop (){ 10 Int Pinstate = Digitalread (tmppin1 ); 11 Digitalwrite (tmppin2, high ); 12 }
Status of the digitalread read pin
Digitalwrite outputs the status to the pin, which is divided into 0 and 1, replaced by low and high respectively.
5. logical operators
&, | ,!