Bonjours à tous, je voulais savoir s'il été possible d'envoyer un tableau contenant plusieurs variables via des module RF HC-12. J'ai fait pas mal d'essais mais rien de très concluant.
Voici mon code :
Emetteur :
#include <SoftwareSerial.h>
SoftwareSerial HC12(2, 3);
void setup() {
Serial.begin(9600);
HC12.begin(9600);
}
void loop() {
int x = analogRead(A5);
int y = analogRead(A4);
int pos[2] = {x, y};
HC12.write(pos);
//Serial.println(pos[0]);
//Serial.println(pos[1]);
delay(50);
}
Et récepteur :
#include <SoftwareSerial.h>
SoftwareSerial HC12(2, 3); // HC-12 TX Pin, HC-12 RX Pin
int x;
int y;
int Led = 8;
int Led2 = 7;
void setup() {
Serial.begin(9600);
HC12.begin(9600);
pinMode(Led, OUTPUT);
pinMode(Led2, OUTPUT);
}
void loop() {
int pos[2]={x, y};
while (HC12.available()) {
pos = HC12.read();
Serial.println(pos[0]);
}
}
void loop() {
int x = analogRead(A5);
int y = analogRead(A4);
int pos[2] = {x, y};
HC12.write(pos, sizeof pos);
//Serial.println(pos[0]);
//Serial.println(pos[1]);
delay(50);
}
Le message d'erreur indique ceci :
no matching function for call to 'SoftwareSerial::write(int [2], unsigned int)'
Pour rendre la chose plus aisée, le mieux est de mettre toutes les variables ou tableaux de variables dans une structure et d'envoyer et recevoir celle-ci.
Pour l'envoi : HC12.write((byte *)Structure, sizeof Structure);
Pour recevoir : HC12.readByte((byte *)Structure, sizeof Structure);