digital_potentiometer.ino 944 B

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