Tag: arduino

将String拆分为String数组

我一直在为arduino编程,但今天我遇到了一个问题,我无法用我非常有限的C知识来解决。 这是怎么回事。 我正在创建一个将串行输入发送到arduino(deviceID,command,commandparameters)的pc应用程序。 这个arduino将把这个命令通过RF发送给其他arduino。 根据deviceID,正确的arduino将执行命令。 为了能够确定我想在“,”上拆分该字符串的deviceID。 这是我的问题,我知道如何在java中轻松地做到这一点(即使不使用标准的分割function),但在C中它是一个完全不同的故事。 你们中的任何人都能告诉我如何让这个工作吗? 谢谢 /* Serial Event example When new serial data arrives, this sketch adds it to a String. When a newline is received, the loop prints the string and clears it. A good test for this is to try it with a GPS receiver that sends out NMEA […]

将字节数组转换为整数而不循环的方法?

(我已经看到了这些问题( 在C 中将字节 转换为Int / uint并将字节数组转换为Int24 )但它们看起来比我想做的更复杂,所以我想我会问。) 我在Arduino / Wiring中做了一些LED矩阵编程。 由于这里可能不相关的原因,我有一个表示LED行的“位状态”的字节数组,我用它来缓冲其他操作的结果。 要实际设置LED(我使用的是Maxim 7219芯片),我需要从字节数组中导出一个整数。 使用Arduino / Wiring bitWrite方法,我的下面的一个简单的例子程序工作,但我想知道是否有一个比循环更快的C方法。 byte dog[8] = {0,0,1,1,1,1,1,0}; byte cat; for (int i = 0; i < 8; i++){ bitWrite(cat, i, dog[7-i]); }

Arduino清洁LCD屏蔽带颜色代码?

我认为如果我能用彩色代码设置LCD Shield的背景会很好。 我发现,我只需要说lcd.clean(0xANYCOLOR) 但还有另外一种方法吗? 也许更好的方法? :P 代码atm: #include LCDShield lcd; void setup() { lcd.init(EPSON); lcd.contrast(40); lcd.clear(0x0000FF); } void loop() { }

减去两个时间间隔

我想减去两个时间间隔。 这里一个时间间隔是5小时30分钟,其他是当前时间。代码写成如下。 main() { int Time1; int Time2; int hour=10; int minute=5; int second=13; int h; int m; int Ntime; Time1=(60*5)+(30); Time2=60*hour+minute; Ntime=Time2-Time1; m=(Ntime%60); Ntime=Ntime/60; h=(int)(Ntime); printf(“hour after subtraction is : %d hour %d min”,h,m) }

String Comparsion:Arduino C.

我正在开发基于Web的家庭自动化系统,所以我的arduino向服务器发送请求并在串行监视器中获得以下响应,以及“loneOn”,这是由于Serial.println(r); 声明。 HTTP/1.1 200 OK Date: Mon, 13 Oct 2014 17:46:03 GMT Server: Apache/2.4.4 (Win32) PHP/5.4.16 X-Powered-By: PHP/5.4.16 Content-Length: 14 Content-Type: text/html loneOn.ltwoOn. loneOn 在另一种情况下,来自服务器的响应将具有loneOff,而不是loneOn,我需要确定它究竟是哪一个。 但这不是现在的重点,我在比较字符串时遇到了麻烦。(响应会在串行监视器中循环,但同样,这不是重点。)这是arduino的代码, #include #include #include #include #include #include #include #include #include #include #include byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte server[] = { 192,168,137,1 } ; […]

关于Arduino上TCP的问题

我正在试验我的Arduino Leonardo和一个简单的C套接字服务器。 C部分必须向Arduino发送一个字符串,但我无法连接到arduino(套接字初始化后C函数被阻塞,无法连接到Arduino)。 C函数代码是: #include #include #pragma comment(lib, “ws2_32.lib”) //Winsock Library int connect() { WSADATA wsa; SOCKET s; struct sockaddr_in server; char* message; printf(“\nInitialising Winsock…”); if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) { printf(“Failed. Error Code : %d”, WSAGetLastError()); return 1; } printf(“Initialised.\n”); //Create a socket if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { printf(“Could […]

如果输入为高电平,则使用arduino GPRS SIM900发送短信一次

我遇到一个问题,如果输入为高,则发送1个短信,如果是低==>没有发送短信,如果低到高==>发送1个短信。 这段代码不能正常工作,只是在我开启GPRS时发送短信,之后什么都没发生。 mclopez帮助了我,谢谢你,但没有工作:(,这是我用delay()编写的新代码,但是同样的问题。 感谢您提前帮助。 #include #include “TimerOne.h” const int DI = 2; const int DT = 3; const int DGP1 = 4; const int DGP2 = 5; const long interval = 100000; // in microseconds int value1 = 0; int value2 = 0; int value3 = 0; int value4 = 0; int value1_old = 0; […]

将MFRC522 UIDhex字节转换为可打印的十进制

我在我的Arduino UNO上使用MFRC522库来阅读Mifare RFID标签信息。 // Print HEX UID Serial.print(“Card UID:”); for (byte i = 0; i < mfrc522.uid.size; i++) { Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(mfrc522.uid.uidByte[i], HEX); } Serial.println(); 我有一个包含HEX UID的字节数组(4): 54 C7 FD 5A 但我没能将它转换为十进制: HEX(5AFDC754) => DEC(1526581076) 我试图将字节数组转换为char反向,但编译器没有让我打印Dec。 char str[8]; int k = 0; for (int i = 3; i […]

Arduino UNO,CC3000:while(client.connected)

我正在玩Arduino UNO和连接到远程Web服务的CC3000屏蔽。 虽然我在循环脚本时遇到问题。 正如您在下面的代码中看到的那样,脚本应该以每5秒occupied一次的状态ping Web服务。 虽然在使用while(client.connected)会让Arduino永久停止/挂起。 即使while(client.connected) {}只是空的。 如果我不包括while(client.connected){}那么Web服务就没有被ping,这就是为什么我发现自己处于相当困境的原因。 请参阅下面的Arduino Sketch文件和下面的序列日志。 #include #include #include #include #include “utility/debug.h” // These are the interrupt and control pins #define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! // These can be any two pins #define ADAFRUIT_CC3000_VBAT 5 #define ADAFRUIT_CC3000_CS 10 // Use hardware SPI for the remaining pins […]

拆分以逗号分隔的整数字符串

我的背景不在C(它在Real Studio中 – 类似于VB)而且我真的很难分割逗号分隔的字符串,因为我不习惯低级字符串处理。 我正在通过串口向Arduino发送字符串。 这些字符串是特定格式的命令。 例如: @20,2000,5! @10,423,0! ‘@’是标题,表示新命令和’!’ 是标记命令结束的终止页脚。 ‘@’之后的第一个整数是命令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() { […]