我正在使用热电偶并下载了MAX6675库.我想知道以下几行中ARDUINO常量的值是多少.
#if ARDUINO >= 100
lcd.write((byte)0);
#else
lcd.print(0, BYTE);
#endif
lcd.print("C ");
lcd.print(thermocouple.readFahrenheit());
#if ARDUINO >= 100
lcd.write((byte)0);
#else
lcd.print(0, BYTE);
#endif
lcd.print('F');
Run Code Online (Sandbox Code Playgroud)
我已经搜索了答案,但却发现了很少的信息.我可以使用以下行打印出值,但我仍然无法找出它的含义.
Serial.println(ARDUINO);
我被告知(特别是在Arduino上的C++标准库,以及Stack Overflow问题C++字符串和Arduino字符串中的答案.如何组合它们?))Arduino编译器没有实现new运算符.但是,我已经为使用它的Arduino(在Arduino IDE中)编写了一个程序,它运行得很好.
void setup() {
Serial.begin(9600);
}
void loop() {
char* array;
char c;
unsigned arraySize;
Serial.write("Enter a 1 digit number.\n");
do {
c = Serial.read();
} while(c < '0' or c > '9');
arraySize = c-'0';
Serial.write("You wrote ");
Serial.write(c);
Serial.write(".\n");
Serial.write("Now enter ");
Serial.write(c);
Serial.write(" lower-case letters.\n");
array = new char[arraySize];
for (unsigned i = 0; i < arraySize;) {
array[i] = Serial.read();
if (array[i] >= 'a' and …Run Code Online (Sandbox Code Playgroud) 我希望有人能解释为什么这段代码不能在 Arduino IDE 中编译(使用 1.0.5)。以下代码仅在 DEBUG=1 时编译,但在设置为 0 时编译。
我希望实现的只是一种在我交换 LED 驱动器时使用相同代码的简单方法,并在重新编译和上传之前翻转 DEBUG 位。
注意:本示例是IDE中要编译的全部代码(不需要其他代码)。
问题代码:
#define DEBUG 0 //DEBUG=1 works, DEBUG=0 causes compiler error
#if DEBUG == 1
int x = 123;
//Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
#else
int x = 567;
//Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();
#endif
void setup() { }
void loop() { }
Run Code Online (Sandbox Code Playgroud)
错误:
core.a(main.cpp.o): In function `main':
C:\arduino\hardware\arduino\cores\arduino/main.cpp:11: undefined reference to `setup'
C:\arduino\hardware\arduino\cores\arduino/main.cpp:14: undefined reference to `loop'
Run Code Online (Sandbox Code Playgroud) 我有以下代码,我需要快速执行,但它需要花费大量时间来改变价值,无论如何更快地完成这项任务?
我正在使用indexOf()并substring()完成这项任务.这是为了改变条形LED的颜色.
// declare LED Series A Pins R-G-B (PWM Pins)
int const AledRedPin = 6;
int const AledGreenPin = 5;
int const AledBluePin = 3;
// declare LED Series B Pins R-G-B (PWM Pins)
int const BledRedPin = 10;
int const BledGreenPin = 11;
int const BledBluePin = 9;
// serial input variable & string
// initialise LED Series A Pins R-G-B (PWN Value: 0 to 255)
// initial value = 255
int AledRed = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在字符串旁边打印一个整数,但是它实际上并没有工作,并且变得很困惑。
int cmdSeries = 3;
Serial.println("Series : " + cmdSeries);// That's where the problem occur
Run Code Online (Sandbox Code Playgroud)
在Visual Basic中,我们以前是这样做的:
Dim cmdSeries As Integer
Console.Writeline(""Series : {0}", cmdSeries)
Run Code Online (Sandbox Code Playgroud)
所以我已经用Serial.println尝试了它,但是它返回了这个错误:重载的'println(const char [14],int&)'的调用是模棱两可的
任何人都可以帮帮我,我想在不使用任何库的情况下以干净的方式实现这一目标。
我正在尝试将一个 cpp 文件添加到具有以下设置的 arduino 项目中...
project
--folder
--foo.h
--foo.cpp
--project.ino
Run Code Online (Sandbox Code Playgroud)
我#include "folder/foo.h在project.ino. 然而,虽然头文件提供了函数的原型,但函数定义在 cpp 文件中。当我尝试使用 Arduino IDE 编译代码时,它失败并显示错误
Undefined reference to 'bar()'
并bar()位于foo.cpp
我看了这个,但我没有设置sketch/import library(但是我有sketch/include library,但是我没有看到任何接近使用自定义文件夹位置的东西)
我也看了这个。但与上述相同,该设置在我的 ide 中不存在。(我最近下载的)
代码
//project.ino
#include "folder/foo.h"
void setup() {
Serial.begin(9600);
}
void loop() {
bar();
}
Run Code Online (Sandbox Code Playgroud)
//folder/foo.h
#include "Arduino.h"
void bar();
Run Code Online (Sandbox Code Playgroud)
//folder/foo.cpp
#include "foo.h"
void bar() {
Serial.println("bar");
}
Run Code Online (Sandbox Code Playgroud)
错误
/tmp/ccNTRFfU.ltrans0.ltrans.o: In function `loop':
/home/temporary/project/project.ino:9: undefined reference to …Run Code Online (Sandbox Code Playgroud) 在arduino上,我需要在类似以下函数中使用Serial.print():
void loop()
{
serial_send(any_type);
}
void serial_send(type message)
{
Serial.print(message);
}
Run Code Online (Sandbox Code Playgroud)
Serial.print可以接受任何类型的变量,例如,作为int,double或String。如何获得相同的行为,serial_send所以不必指定类型?
在预处理器中尝试将数字相乘时,Arduino 给了我意想不到的值。
例如
#define msPerDay (24 * 60 * 60 * 1000)
void setup() {
Serial.begin(9600);
Serial.println(msPerDay);
}
void loop() {}
Run Code Online (Sandbox Code Playgroud)
这应该输出 86400000 但我得到
23552
Run Code Online (Sandbox Code Playgroud)
在串行监视器中。还
#define msPerDay (60 * 1000)
void setup() {
Serial.begin(9600);
Serial.println(msPerDay);
}
void loop() {}
Run Code Online (Sandbox Code Playgroud)
应该输出 60000 而是打印
-5536
Run Code Online (Sandbox Code Playgroud)
为什么这会给我这些意想不到的值,C++ 用来计算#define 乘法的规则是什么?
所以我一直在为我的arduino编程,这是c ++的一些变体.我一直在编写一个程序来勾选每个4位七段显示器的数字.我一直无法将引脚[]设置为不同长度的不同阵列.
例如,显示一个装置将打开2个引脚,这些引脚在阵列中表示int one[] = {1,2};并显示四个引脚int four[] = {1,2,3,4};.
我一直在尝试的是:
int pins[] = null;
int one[] = {1,2};
int four[] = {1,2,3,4};
switch(num) {
case 1: pins = one; break;
case 4: pins = four; break;
}
Run Code Online (Sandbox Code Playgroud)
然而,这已经造成了问题,并且不允许我上传它,因为事情到处都是破坏.
我对c ++知之甚少,只是它与Java类似,我对此非常了解.
我觉得我喂养的鲨鱼没有足够的保护,我的代码中的这一点让我烦恼.
我的问题是你如何初始化一个数组,但稍后再改变它?
此示例草图显示了如何使用setCursor()方法重新定位光标。要移动光标,只需调用具有行和列位置的setCursor()即可。例如,对于2x16显示器:
lcd.setCursor(0, 0); // top left
lcd.setCursor(15, 0); // top right
lcd.setCursor(0, 1); // bottom left
lcd.setCursor(15, 1); // bottom right
Run Code Online (Sandbox Code Playgroud)
我无法理解以上代码。任何人都可以提供相同的说明吗?
arduino ×10
arduino-ide ×10
c++ ×4
arduino-uno ×3
arduino-c++ ×1
arrays ×1
lcd ×1
new-operator ×1