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