/*
* Simple Touch Potentiometer Example with Arduino
*
* Reads the pot value and controls the brightness of the Ardu
ino LED on
* Digital Pin 13. Also logs new values to the serial port.
Utilizes
* both the direct and indirect command interface forms.
*
* Assumes Touch Pot is at I2C Address 8
*
* Released into the public domain by Dan Julio. This softwar
e is supplied on an asis
* basis and no warranty as to its suitability for any particu
lar purpose is either made
* or implied. danjuliodesigns, LLC. will not accept any clai
m for damages howsoever
* arising as a result of use or failure of this software.
*/
#include "Wire.h"
int i2cAddr = 8; // Direct access at i2cAddr, indirect registe
rs at i2cAddr+1
uint8_t prevValue;
uint8_t curValue;
void setup() {
Serial.begin(115200);
Wire.begin();
pinMode(13, OUTPUT);
// Demonstrate access to Touch Potentiometer registers
WriteTpReg(1, 128); // set to 50% by writing to register 1
curValue = ReadTpReg(1); // read back value just set
// Set Arduino LED PWM to match
analogWrite(13, curValue);
prevValue = curValue;
}
void loop() {
delay(50); // Read ~20 times/second
// Demonstrate direct access to Touch Potentiometer value
curValue = ReadTpValue(); // faster I2C access than registe
r read
if (curValue != prevValue) {
analogWrite(13, curValue);
Serial.println(curValue);
prevValue = curValue;
}
}
// Write a Touch Potentiometer register
void WriteTpReg(uint8_t addr, uint8_t data) {
Wire.beginTransmission(i2cAddr+1);
Wire.write('W');
Wire.write(addr);
Wire.write(data);
Wire.endTransmission();
}
// Get the Touch Potentiometer value
Page 12 of 14
Need help?
Do you have a question about the PRT-13144 and is the answer not in the manual?
Questions and answers