我已经尝试了所有Google的能力,但似乎无法解决这个问题.我正在尝试返回一个字符并传递给另一个没有运气的函数.我需要做某种内存位置吗?
char hostname[] = "www.XXXXX.com";
uint8 ipaddr[] = {XXX,XXX,XXX,XXX};
char uri[] = "/api/Login/";
char key[] = API_KEY; //3490324032-asdfasd-234234
const int port = 80;
//function to combine uri and key
char combine(char key[], char uri[]) {
int i = 0;
int x = 0;
char long_s[sizeof(uri) + sizeof(key)];
while(uri[i]) {
long_s[i] = uri[i];
++i;
}
while(key[x]) {
long_s[i] = key[x];
++i;
++x;
}
long_s[i] = '\0';
//Serial.print(long_s);
return long_s; //pointer?
}
char lon = combine (key, uri);
char* newURI = &lon; …Run Code Online (Sandbox Code Playgroud) 我的背景不在C(它在Real Studio中 - 类似于VB)而且我真的很难分割逗号分隔的字符串,因为我不习惯低级字符串处理.
我正在通过串口向Arduino发送字符串.这些字符串是特定格式的命令.例如:
@20,2000,5!
@10,423,0!
Run Code Online (Sandbox Code Playgroud)
'@'是标题,表示新命令和'!' 是标记命令结束的终止页脚.'@'之后的第一个整数是命令id,其余的整数是数据(作为数据传递的整数数可以是0-10个整数).
我写了一个获取命令的草图(剥离了'@'和'!')并调用了一个函数,handleCommand()当有一个命令要处理时.问题是,我真的不知道如何拆分这个命令来处理它!
这是草图代码:
String command; // a string to hold the incoming command
boolean commandReceived = false; // whether the command has been received in full
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// main loop
handleCommand();
}
void serialEvent(){
while (Serial.available()) {
// all we do is construct the incoming command to be handled in the main loop
// …Run Code Online (Sandbox Code Playgroud) const int pingPin = 7;
const int ledPin = 11;
const int ledPin2 = 10;
int ledLevel = 0;
int ledLevel2 = 255;
int constraint = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
constraint = constrain(duration, 500, 8000);
ledLevel = map(constraint, 500, 8000, 255, 0);
if (ledLevel < 192) {
analogWrite(ledPin, ledLevel);
ledLevel2 = ledLevel2 - 255;
} …Run Code Online (Sandbox Code Playgroud) 在Arduino IDE中,我收到有关如何声明我的构造函数两次的错误.
这是它的代码:
tond.h
#ifndef TOND_H
#define TOND_H
class Tondeuse {
public:
Tondeuse();
Tondeuse(int,int);
};
#endif
Run Code Online (Sandbox Code Playgroud)
tond.cpp
#ifndef TOND
#define TOND
#include "arduino.h"
#include "tond.h"
Tondeuse::Tondeuse()
{
}
Tondeuse::Tondeuse(int h, int w)
{
Serial.println("Hello");
}
#endif
Run Code Online (Sandbox Code Playgroud)
而错误:
Tondeuse.cpp.o: In function `Tondeuse':
/tond.cpp:11: multiple definition of `Tondeuse::Tondeuse()'
tond.cpp.o:C:\Users\DEPANNE\AppData\Local \Temp\build6942484698459603114.tmp/tond.cpp:11: first defined here
Tondeuse.cpp.o: In function `Tondeuse':
/tond.cpp:11: multiple definition of `Tondeuse::Tondeuse()'
tond.cpp.o:C:\Users\DEPANNE\AppData\Local \Temp\build6942484698459603114.tmp/tond.cpp:11: first defined here
Tondeuse.cpp.o: In function `Tondeuse':
/tond.cpp:16: multiple definition of `Tondeuse::Tondeuse(int, int)'
tond.cpp.o:C:\Users\DEPANNE\AppData\Local\Temp\build6942484698459603114.tmp/tond.cpp:16: first defined here
Tondeuse.cpp.o: …Run Code Online (Sandbox Code Playgroud) 我正在从Arduino(c语言)切换到Netduino(c#语言).
在我的arduino程序中,我有以下功能(内置):
我想将其转换为C#.我有以下代码:
int ConstrainValue(int value, int min, int max)
{
int Value = value;
int Min = min;
int Max = max;
if (Value >= Max)
{
Value = Max;
return Value;
}
else if (Value <= Max)
{
Value = Min;
return Value;
}
return Value;
}
Run Code Online (Sandbox Code Playgroud)
但是,我也希望能够将其用于double数据类型.是否可以修改函数以便可以使用多种数据类型?
我正在尝试在Arduino上获取要由我的C#程序联系的代码,以打开和关闭板载(插针13)LED。这是我已加载到Arduino中的代码:
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop()
{
if (Serial.available() > 0)
{
int b = Serial.read();
if (b == 1)
{
digitalWrite(13, HIGH);
}
else if (b == 0)
{
digitalWrite(13, LOW);
}
Serial.flush();
}
}
Run Code Online (Sandbox Code Playgroud)
我找到并下载了此代码,并使LED正常工作!(万岁!)
我尝试使用简单的OnButton和OffButton将代码反向工程为我自己的代码,但无法正常工作。有人可以看看下面的代码,并告诉我是否缺少明显的内容。
using System.IO;
using System.IO.Ports;
public static System.IO.Ports.SerialPort serialPort1;
private delegate void LineReceivedEvent(string line);
private void establishConnection()
{
System.CompnentModel.IContainer components = new System.ComponentModel.Container();
serialPort1 = new System.IO.Ports.SerialPort(components);
serialPort1.PortName = "COM7";
serialPort1.BaudRate = 9600;
serialPort1.DtrEnable = true;
serialPort1.Open(); …Run Code Online (Sandbox Code Playgroud) 更新:我甚至无法使用此计算器来重现本数据表图8和图9中所示的SMBus PEC !
所以我将arduino与Melexis温度传感器连接起来,并且它没有问题 - 除了我似乎无法使CRC检查工作.
我已经成功完成了读取操作(尽管我的软件忽略了数据包错误代码)但我已经尝试了很多CRC8的实现来检查PEC字节无济于事.我现在使用的代码块来自OneWire:
uint8_t OneWire::crc8(const uint8_t *addr, uint8_t len)
{
uint8_t crc = 0;
while (len--) {
uint8_t inbyte = *addr++;
for (uint8_t i = 8; i; i--) {
uint8_t mix = (crc ^ inbyte) & 0x01;
crc >>= 1;
if (mix) crc ^= 0x8C;
inbyte >>= 1;
}
}
return crc;
}
Run Code Online (Sandbox Code Playgroud)
我重写它只考虑一个字节:
int smbCRC(int message) {
uint8_t crc = 0;
uint8_t inbyte = message & 0xFF;
for (uint8_t i = …Run Code Online (Sandbox Code Playgroud) 如果我从WotClass.h注释掉#define行,我得到了编译错误: WotClass.cpp:7: error: 'BFLM_DEFINE' was not declared in this scope
它不是假设与范围无关吗?或者是订单中的问题?
WotClass.h
#ifndef WOTCLASS_H
#define WOTCLASS_H
#define BFLM_DEFINE 1 // if commented out then compile fails.
class WotClass{
public:
WotClass();
int foo();
private:
};
#endif
Run Code Online (Sandbox Code Playgroud)
WotClass.cpp
#include "WotClass.h"
WotClass::WotClass(){}
int WotClass::foo(){
return BFLM_DEFINE;
}
Run Code Online (Sandbox Code Playgroud)
Test.ino
#define BFLM_DEFINE 1 // This is before including class
#include "WotClass.h"
void setup(){
Serial.begin(115200);
Serial.println(BFLM_DEFINE);
WotClass x;
Serial.print(x.foo());
}
void loop(){}
Run Code Online (Sandbox Code Playgroud) 我需要我的Arduino代码打印出被替换为变量的随机单词.因此,就像我将有一个随机数生成器一样,随机数字吐出一个单词,然后作为一个变量需要打印出来.这是我现在的代码,对不起,我还是Arduino的初学者.
long randnumber = 0;
int aye = 1;
int sup = 2;
int boi = 3;
int bruv = 4;
void setup() {
Serial.begin(9600); // Starts the serial communication
}
void loop() {
int randnumber = 0;
randnumber = random(0,4);
Serial.println(randnumber);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用DHT传感器
WifiConfig.h
#include "DHT.h"
class WifiConfig
{
public:
WifiConfig();
std::unique_ptr<DHT> dht;
void initialize(char const *ssid, char const *psk);
}
Run Code Online (Sandbox Code Playgroud)
WifiConfig.cpp
#include "WifiConfig.h"
WifiConfig::WifiConfig() {}
void WifiConfig::initialize(char const *ssid, char const *psk) {
dht.reset(new DHT(DHTPin, DHT11));
dht.readTemperature(); // doesnt work
}
Run Code Online (Sandbox Code Playgroud)
以这种方式在我的班级中使用另一个班级的正确方法是什么?