update arduino code
This commit is contained in:
parent
10ffa1bf0e
commit
88e64184f8
@ -2,25 +2,38 @@
|
||||
* Official proxy code for iTender GPIO Communication
|
||||
**/
|
||||
|
||||
#include "HX711.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
DynamicJsonDocument<200> doc;
|
||||
const int BUFFER_SIZE = 256;
|
||||
char buffer[BUFFER_SIZE];
|
||||
int bufferIndex = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
while (!Serial) continue;
|
||||
|
||||
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
if( Serial.available() > 0 )
|
||||
{
|
||||
String data = Serial.readString();
|
||||
|
||||
if (Serial.available() > 0) {
|
||||
char incomingByte = Serial.read();
|
||||
buffer[bufferIndex] = incomingByte;
|
||||
bufferIndex++;
|
||||
|
||||
if (incomingByte == '\n') {
|
||||
buffer[bufferIndex] = '\0';
|
||||
bufferIndex = 0;
|
||||
|
||||
StaticJsonDocument<200> doc;
|
||||
DeserializationError error = deserializeJson(doc, buffer);
|
||||
if (error) {
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// Do something with the deserialized JSON object
|
||||
int value = doc["value"];
|
||||
Serial.println(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user