Week 02
This week I learned a lot about sensor, digital input and output and analog input.
Notes
Data types
-
int is an integer data type, takes up 16 bits which can contain 216 different values, And they can be positive or negative. One bit used to store the plus or minus sign.
-
byte takes up 8 bits(0-255), only the positive number
-
long can store very large values, so usually we can use it to store the number of milliseconds since the program started.
-
boolean only true or false
Input & Output
-
Digital input When the external physical state has only two (LOW/ HIGH) uses
-
Digital output controlling the objects switch
-
digitalRead read it for the values 1 (HIGH) or 0 (LOW)
-
digitalWrite to set the pin high or low
-
Analog Input A range of states
-
analogRead Read a range of values
-
analogWrite to give Pin(digitalModel (pin, OUTPUT) a value
Test
Tips
-
Attention to Chinese characters and English characters
-
Pay attention to the Pin name on the Arduino
-
When writing code, you can first write out the code logic in comments
-
millis() This function is used to return the number of milliseconds it took for the Arduino board to start running the current program.
-
A digital pin can store 256 characters, but the sensor can store 1024. In this case, you need to use value=map(analogValue, Min,Max,0,255); and because the maximum and minimum values may be inaccurate, you have to control the value in a certain range. Use value=constrain(value,0,225);