arduino 0x01

This commit is contained in:
Sergio Pernas 2022-03-25 17:09:45 -03:00
parent 2c3df9d549
commit f45f27b254

View file

@ -1,30 +1,16 @@
int inData; int inData;
const char* valueSensor;
char sensorValue = "10";
const byte devID = 0x01; const byte devID = 0x01;
int errCode;
char sendData[3];
typedef struct {
char senType; char *senData[] {
char senValue; "T", // Tipo de sensor
char senUnit; "s", // Lectura del sensor
"C"
} senFrame;
void newFrame (senFrame *pt, char sensor) {
pt-> senType = "hum";
pt-> senValue = "10.5";
pt-> senUnit = "%";
for ( byte i = 0; i < 4; i++) sendData[i] = ( ((byte *)pt)[i] );
Serial.println (sendData[sensor]);
}
};
@ -34,12 +20,21 @@ void setup() {
} }
void loop() { void loop() {
if ( Serial.available() > 0) { if ( Serial.available() > 0) {
inData = Serial.read();
switch (inData) { switch (inData) {
case devID: case devID:
newFrame();
Serial.write(devID);
for (int i = 0; i <= 3; i++) {
Serial.write(senData[i]);
}
Serial.write("99");
break; break;
} }