//master
char charVal[6];
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
float temperature = analogRead(A0);
temperature = temperature/1023*5;
temperature = temperature*100-50;
//this is a float we want it as a c-string:
//5 is min width, 1 is precision; float value is copied to charVal
dtostrf(temperature, 5, 1, charVal);
Serial.write(charVal); //Write the serial data
delay(1000);
}
---------------
//slave
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd1(0x20,16,2);
char mystr[10]; //Initialized variable to store recieved data
void setup() {
Serial.begin(9600);
lcd1.init();
lcd1.clear();
lcd1.backlight();
}
void loop() {
Serial.readBytes(mystr, 5); //Read the serial data and store in var
lcd1.setCursor(0,0);
lcd1.print("Temp ");
lcd1.print(mystr);
delay(1000);
}
reference:
No comments:
Post a Comment