source: rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.pde@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 975 bytes
Line 
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
17void setup()
18{
19 Wire.begin(); // join i2c bus (address optional for master)
20}
21
22byte val = 0;
23
24void 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.