Salve a tutti , sono ritornato a dare un'occhiata agli HC-05.....Nello specifico vorrei inviare un valore di lettura di un dht22
La mia domanda è questo codice (trovato in rete) permette l'invio del valore di una lettera di un potenziometro. Come mai se provo a modificarlo per la lettura di un dht22, il master non riceve nessun valore?
Cambio solamente il nome della variabile che invia e smaltisco le parti inutili di codice.
Altra domanda: come potrei inviare 2 valori ? Devo scomporre l'intero e poi ricomporlo in ricezione come si fa con l'i2c?
Grazie a chi mi risponderà e Buon Ferragosto
* == MASTER CODE ==
*/
#define ledPin 9
int state = 0;
int potValue = 0;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(38400); // Default communication rate of the Bluetooth module
}
void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
}
// Controlling the LED
if (state == '1') {
digitalWrite(ledPin, HIGH); // LED ON
state = 0;
}
else if (state == '0') {
digitalWrite(ledPin, LOW); // LED ON
state = 0;
}
// Reading the potentiometer
potValue = analogRead(A0);
int potValueMapped = map(potValue, 0, 1023, 0, 255);
Serial.write(potValueMapped); // Sends potValue to servo motor
delay(10);
}
== SLAVE CODE ==
*/
#include <Servo.h>
#define button 8
Servo myServo;
int state = 20;
int buttonState = 0;
void setup() {
pinMode(button, INPUT);
myServo.attach(9);
Serial.begin(38400); // Default communication rate of the Bluetooth module
}
void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
}
// Controlling the servo motor
myServo.write(state);
delay(10);
// Reading the button
buttonState = digitalRead(button);
if (buttonState == HIGH) {
Serial.write('1'); // Sends '1' to the master to turn on LED
}
else {
Serial.write('0');
}
}