File tree 1 file changed +43
-0
lines changed
libraries/Wire/examples/digital_potentiometer_timeout
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ // I2C Digital Potentiometer with timeout
2
+ // originally
3
+ // by Nicholas Zambetti <http://www.zambetti.com>
4
+ // and Shawn Bonkowski <http://people.interaction-ivrea.it/s.bonkowski/>
5
+
6
+ // Demonstrates use of the Wire library with timeout
7
+ // Controls AD5171 digital potentiometer via I2C/TWI
8
+
9
+ // Created 7 July 2020
10
+
11
+ // This example code is in the public domain.
12
+
13
+ const uint32_t timeout = 5000 ; // microseconds, 0 = infinite, default = 25000
14
+ const bool reset = true ; // true = force TWI reset if timeout occurs, default = false
15
+
16
+ #include < Wire.h>
17
+
18
+ void setup () {
19
+ Wire.begin (); // join i2c bus (address optional for master)
20
+ Wire.setWireTimeout ( timeout, reset );
21
+ }
22
+
23
+ byte val = 0 ;
24
+ int count = 0 ;
25
+
26
+ void loop () {
27
+ Wire.beginTransmission (44 ); // transmit to device #44 (0x2c)
28
+ // device address is specified in datasheet
29
+ Wire.write (byte (0x00 )); // sends instruction byte
30
+ Wire.write (val); // sends potentiometer value byte
31
+ Wire.endTransmission (); // stop transmitting
32
+
33
+ if ( Wire.getWireTimeoutFlag () ) {
34
+ // handle timeout
35
+ count++;
36
+ }
37
+
38
+ val++; // increment value
39
+ if (val == 64 ) { // if reached 64th position (max)
40
+ val = 0 ; // start over from lowest value
41
+ }
42
+ delay (500 );
43
+ }
You can’t perform that action at this time.
0 commit comments