在用惯KEIL之后再用ARDUINO会出现一些不适应的问题,因此本文写一下目前使用arduino遇到的问题以及相关方法。
1、arduino写函数时,如果全写在ino里面会显得非常乱,但是有些项目需要很多东西来配置,因此需要写在。c以及。h中。但是对于arduino来说,创建新文件需要的后缀与KEIL不一样,不同于keil,后缀改为cpp
1.点击新建标签页。
2.写入新的文件名,.C文件后缀为。cpp不然会报错,。h文件正常。
3. .h文件与.CPP文件需要写入
。h文件
#ifndef __MAIN_H
#define __MAIN_H
#include "Arduino.h"
extern unsigned char TX_485[8];
void mian_set(void);
void whil_run_loop(void);
#endif
。cpp文件
#include "main.h"
int cnt_cli_485 = 0;
unsigned char TX_485[]={0x03,0X03,0X01,0XF4,0X00,0X08,0X05,0XE0};
void mian_set(void)
{
}
void whil_run_loop(void)
{
}
4.。ino文件中
#include "main.h"
void setup() {
// put your setup code here, to run once:
mian_set();
}
void loop() {
// put your main code here, to run repeatedly:
whil_run_loop();
}
如上基本可以按照KEIL习惯来编写Arduino程序。
2、在使用wifi函数时,会遇到想要创建一个wificlient和PubSubClient,在。h中引出去。正确的external方法:
extern WiFiClient espClient;
extern PubSubClient client;
这样别的文件用的时候就方便很多。
其他配置和设置参考例程以及学习文档。