Skip to content

Added new Wire functions into libraries/Wire/keywords.txt #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// I2C Digital Potentiometer with timeout
// originally
// by Nicholas Zambetti <http://www.zambetti.com>
// and Shawn Bonkowski <http://people.interaction-ivrea.it/s.bonkowski/>

// Demonstrates use of the Wire library with timeout
// Controls AD5171 digital potentiometer via I2C/TWI

// Created 7 July 2020

// This example code is in the public domain.

const uint32_t timeout = 5000; // microseconds, 0 = infinite, default = 25000
const bool reset = true; // true = force TWI reset if timeout occurs, default = false

#include <Wire.h>

void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Wire.setWireTimeout( timeout, reset );
}

byte val = 0;
int count = 0;

void loop() {
Wire.beginTransmission(44); // transmit to device #44 (0x2c)
// device address is specified in datasheet
Wire.write(byte(0x00)); // sends instruction byte
Wire.write(val); // sends potentiometer value byte
Wire.endTransmission(); // stop transmitting

if ( Wire.getWireTimeoutFlag() ) {
// handle timeout
Wire.clearWireTimeoutFlag();
count++;
}

val++; // increment value
if (val == 64) { // if reached 64th position (max)
val = 0; // start over from lowest value
}
delay(500);
}
2 changes: 2 additions & 0 deletions libraries/Wire/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ endTransmission KEYWORD2
requestFrom KEYWORD2
onReceive KEYWORD2
onRequest KEYWORD2
setWireTimeout KEYWORD2
getWireTimeoutFlag KEYWORD2

#######################################
# Instances (KEYWORD2)
Expand Down