PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

40 行
975B

  1. // I2C Digital Potentiometer
  2. // by Nicholas Zambetti <http://www.zambetti.com>
  3. // and Shawn Bonkowski <http://people.interaction-ivrea.it/s.bonkowski/>
  4. // Demonstrates use of the Wire library
  5. // Controls AD5171 digital potentiometer via I2C/TWI
  6. // Created 31 March 2006
  7. // This example code is in the public domain.
  8. // This example code is in the public domain.
  9. #include <Wire.h>
  10. void setup()
  11. {
  12. Wire.begin(); // join i2c bus (address optional for master)
  13. }
  14. byte val = 0;
  15. void loop()
  16. {
  17. Wire.beginTransmission(44); // transmit to device #44 (0x2c)
  18. // device address is specified in datasheet
  19. Wire.write(byte(0x00)); // sends instruction byte
  20. Wire.write(val); // sends potentiometer value byte
  21. Wire.endTransmission(); // stop transmitting
  22. val++; // increment value
  23. if(val == 64) // if reached 64th position (max)
  24. {
  25. val = 0; // start over from lowest value
  26. }
  27. delay(500);
  28. }