Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. //MASTER
  2. #include <Wire.h>
  3. char msg[13];
  4. void setup()
  5. {
  6. // Start I²C bus as master
  7. Wire.begin();
  8. Serial.begin(9600);
  9. }
  10.  
  11. void loop()
  12. {
  13. Wire.requestFrom(8, 11); // request 11 bytes from slave device #8. 11 bytes because 5 digits for temp, 5 digits for hum, and 1 digit for a comma
  14.  
  15. //gathers data comming from slave
  16. int i=0; //counter for each bite as it arrives
  17. while (Wire.available()) {
  18. msg[i] = Wire.read(); // every character that arrives it put in order in the empty array "t"
  19. i=i+1;
  20. }
  21.  
  22. Serial.println(msg); //shows the data in the array hum
  23. delay(500); //give some time to relax
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement