PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

40 lines
913B

  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. }