PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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