小编mpf*_*aga的帖子

确定Arduino的板类型

如何在编译时确定Arduino的板类型(例如Uno vs Nano)?不要与确定处理器类型相混淆.正如我看到的例子#if defined(__ AVR_ATmega32U4__)......

类似地,我想要一种方法来确定Arduino的各种风格都使用相同的ATmega328处理器.

IDE知道董事会.因此可以从一些预编译器#IF访问它

与Uno相比,Nano有不同的中断.因此,在编译时了解板类型可以自动化公共库的引脚分配.

arduino precompiler

11
推荐指数
1
解决办法
9468
查看次数

覆盖库中的#define

我为一个设备创建了一个Arduino库,它通常可以通过多种方式配置.例如,使用中断或轮询它.在其他示例中,我创建了以下文件:foo.h,fooConfig.h和foo.cpp,如下所示.其中fooConfig.h包含如何使用屏蔽的配置.如有或没有中断等......

在这样做时,我希望主草图的INO文件能够覆盖默认设置,这些设置已使用#define声明.包括在图书馆的实例中.结果表明它确实如此.至少我这样做的方式.

下面的代码是一个带有问题的简化示例:

definetest.ino

#define BAR USE_POLL
#include <foo.h>

foo test;

void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.print(F("setup's defined BAR was "));
  Serial.println(BAR);

  Serial.print(F("inside foo.begin defined BAR was "));
  Serial.println(test.begin());
}

void loop() {
}
Run Code Online (Sandbox Code Playgroud)

foo.h中

#ifndef FOO_h
#define FOO_h

#include "FOOConfig.h"

class foo {
  public:
    int begin();
};
#endif // FOO_h
Run Code Online (Sandbox Code Playgroud)

FooConfig.h

 #ifndef FOOCONFIG_h
  #define FOOCONFIG_h

  #define USE_INT      1
  #define USE_POLL     2

  #ifndef BAR
    //default to using interrupts
    #define BAR USE_INT
  #endif // BAR

#endif  // FOOCONFIG_h
Run Code Online (Sandbox Code Playgroud)

Foo.cpp中

#include <foo.h> …
Run Code Online (Sandbox Code Playgroud)

c ide arduino c-preprocessor

7
推荐指数
1
解决办法
6437
查看次数

标签 统计

arduino ×2

c ×1

c-preprocessor ×1

ide ×1

precompiler ×1