Last change
on this file since 136 was 136, checked in by ertl-honda, 8 years ago |
ライブラリとOS及びベーシックなサンプルの追加.
|
File size:
975 bytes
|
Rev | Line | |
---|
[136] | 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 | // This example code is in the public domain.
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | #include <Wire.h>
|
---|
| 16 |
|
---|
| 17 | void setup()
|
---|
| 18 | {
|
---|
| 19 | Wire.begin(); // join i2c bus (address optional for master)
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | byte val = 0;
|
---|
| 23 |
|
---|
| 24 | void loop()
|
---|
| 25 | {
|
---|
| 26 | Wire.beginTransmission(44); // transmit to device #44 (0x2c)
|
---|
| 27 | // device address is specified in datasheet
|
---|
| 28 | Wire.write(byte(0x00)); // sends instruction byte
|
---|
| 29 | Wire.write(val); // sends potentiometer value byte
|
---|
| 30 | Wire.endTransmission(); // stop transmitting
|
---|
| 31 |
|
---|
| 32 | val++; // increment value
|
---|
| 33 | if(val == 64) // if reached 64th position (max)
|
---|
| 34 | {
|
---|
| 35 | val = 0; // start over from lowest value
|
---|
| 36 | }
|
---|
| 37 | delay(500);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.