PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

master_reader.ino 913B

3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839
  1. // Wire Master Reader
  2. // by Nicholas Zambetti <http://www.zambetti.com>
  3. // Demonstrates use of the Wire library
  4. // Reads data from an I2C/TWI slave device
  5. // Refer to the "Wire Slave Sender" example for use with this
  6. // Created 29 March 2006
  7. // This example code is in the public domain.
  8. #include <Wire.h>
  9. int led = LED_BUILTIN;
  10. void setup()
  11. {
  12. pinMode(led, OUTPUT);
  13. Wire.begin(); // join i2c bus (address optional for master)
  14. Serial.begin(9600); // start serial for output
  15. }
  16. void loop()
  17. {
  18. Serial.print("read: ");
  19. digitalWrite(led, HIGH); // briefly flash the LED
  20. Wire.requestFrom(8, 6); // request 6 bytes from slave device #8
  21. while(Wire.available()) { // slave may send less than requested
  22. char c = Wire.read(); // receive a byte as character
  23. Serial.print(c); // print the character
  24. }
  25. Serial.println();
  26. digitalWrite(led, LOW);
  27. delay(500);
  28. }