当前位置:首页 > 未分类 > 正文内容

Arduino语言参考

lcpsky2年前 (2022-10-23)未分类369

<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=36990266&auto=1&height=66"></iframe>

1602.png

Arduino编程语言可以被分为三个主要部分:函数,值(变量和常量),结构。

函数

用来控制主板和进行数值计算。

Digital I/O (数字I/O函数)

digitalRead() 读取数字引脚值
digitalWrite() 向数字引脚写入值
pinMode() 设置引脚状态(工作在输入还是输出)

Analog I/O (模拟I/O函数)

analogRead() 读取模拟引脚值
analogReference()
analogWrite() 向模拟引脚写入值

Zero, Due & MKR Family

analogReadResolution()
analogWriteResolution()

Advanced I/O (高级I/O函数)

noTone()
pulseIn()
pulseInLong()
shiftIn()
shiftOut()
tone()

Time (时间函数)

delay()
delayMicroseconds()
micros()
millis()

Math (数学函数)

abs()
constrain()
map()
max()
min()
pow()
sq()
sqrt()

Trigonometry (三角函数)

cos()
sin()
tan()

Characters(字符函数)

isAlpha()
isAlphaNumeric()
isAscii()
isControl()
isDigit()
isGraph()
isHexadecimalDigit()
isLowerCase()
isPrintable()
isPunct()
isSpace()
isUpperCase()
isWhitespace()
Random Numbers
random()
randomSeed()

Bits and Bytes(位与比特操作函数)

bit()
bitClear()
bitRead()
bitSet()
bitWrite()
highByte()
lowByte()

External Interrupts(中断函数)

attachInterrupt()
detachInterrupt()

Interrupts(中断函数)

interrupts()
noInterrupts()

Communication(通信)

Serial
Stream

USB

Keyboard
Mouse

VARIABLES(值)

Arduino 数据类型与常量

Constants(常量)

Floating Point Constants
Integer Constants
HIGH | LOW
INPUT | OUTPUT | INPUT_PULLUP
LED_BUILTIN
true | false

Conversion(值转换常数)

(unsigned int)
(unsigned long)
byte()
char()
float()
int()
long()
word()
Data Types
String()
array
bool
boolean
byte
char
double
float
int
long
short
size_t
string
unsigned char
unsigned int
unsigned long
void
word

Variable Scope & Qualifiers

const
scope
static
volatile
Utilities
PROGMEM
sizeof()
STRUCTURE

The elements of Arduino (C++) code.

Sketch

loop()
setup()

Control Structure

break
continue
do...while
else
for
goto
if
return
switch...case
while

Further Syntax

#define (define) 
#include (include) 
/* */ (block comment) 
// (single line comment) 
; (semicolon) 
{} (curly braces) 

Arithmetic Operators
% (remainder) 
* (multiplication) 
+ (addition) 
- (subtraction) 
/ (division) 
 = (assignment operator) 
 Comparison Operators
 != (not equal to) 
 < (less than) 
 <= (less than or equal to) 
 == (equal to) 
> (greater than) 
> = (greater than or equal to) 

Boolean Operators
! (logical not) 
&& (logical and) 
|| (logical or) 
Pointer Access Operators
& (reference operator) 
* (dereference operator) 

Bitwise Operators
& (bitwise and) 
<< (bitshift left) 
 (bitshift right) 
 ^ (bitwise xor) 
 | (bitwise or) 
 ~ (bitwise not) 
 Compound Operators
 %= (compound remainder) 
 &= (compound bitwise and) 
 *= (compound multiplication) 
 ++ (increment) 
 += (compound addition) 
 -- (decrement) 
 -= (compound subtraction) 
 /= (compound division) 
 ^= (compound bitwise xor) 
 |= (compound bitwise or)

Arduino uno

通用性最好,使用范围最广的开发板,大小适中,集合可以部署在任何的环境。拥有大量的扩展模块,如wifi,NFC,I/O扩展模块板,蓝牙。它有13个数字接口,6个模拟接口(A0-A5),1个5V,一个3.3V电源引脚。

模拟端口和数字端口

arduino uno 开发板的端口在它的两侧。它们作一种连接来实现开发板与传感器、执行器以及其他设备的交互。主板的端口支持数字和模拟两种信号。端口都是双向性的,可以通过编程进行定义。

模拟信息

随着时间持续变化的信号,是随时间变化的电压。Arduino uno接口使用了0到1023来描述一个模拟输入信号。某些被标记PWM或者~的端口可以创建一个0-255之间变化的输出信号。

Analog I/O (模拟I/O函数)

analogRead() 读取模拟引脚值
analogReference()
analogWrite() 向模拟引脚写入值

例子:

void setup() {
   pinMode(lcdlight,OUTPUT);
   analogWrite(lcdlight, 130);//用于调节对比度(0-255),替代电位器作用     
}

### 数字信息

数字信号只包含两个值0-1。从3.5-5V之间电压被看做是1,从0-2.5V之间的电压被称为0。

**Digital I/O  (数字I/O函数)**

 digitalRead()  读取数字引脚值
 digitalWrite()  向数字引脚写入值
 pinMode()  设置引脚状态(工作在输入还是输出) 

## Python编程

### PySerial

1. 下载pyserial.exe
2. 双击安装pyserial

Python代码,从串口接收消息

```python
from time import sleep
import serial
port = Serial.Serial(‘/dev/...’,9600)
while True:
    print port.readline()
    sleep(0.2)
    
    
执行python SerialPython.py


扫描二维码推送至手机访问。

版权声明:本文由软件技术记录发布,如需转载请注明出处。

本文链接:https://lcpsky.top/?id=26

分享给朋友:

“Arduino语言参考” 的相关文章

​shiro反序列化漏洞综合利用工具v2.2

​shiro反序列化漏洞综合利用工具v2.2

shiro默认使用了CookieRememberMeManager,其处理cookie的流程是:得到rememberMe的cookie值-->Base64解码-->AES解密-->反序列化。然而AES的密钥是硬编码的,就导致了攻击者可以构造恶意数据造成反序列化的RCE漏洞。使用方式...

git的ignore文件不生效问题

 git rm -r --cached ignoreFile(ignoreFile就是你想忽略的文件),让git不再tracking这些文件。...

Yolov5解析conv,bn,relu,pooling

Yolov5解析conv,bn,relu,pooling

【机器学习】卷积层,池化层,全连接层,BN层作用;CNN 网络参数数量的计算官方文档:https://keras.io/layers/convolutional/#zeropadding2dhttps://blog.keras.io/building-powerful-image-classific...