Last active
June 8, 2023 13:47
-
-
Save rpoisel/3cc82261b184e73cc66df9aeb3564d49 to your computer and use it in GitHub Desktop.
Interfacing DS3502 chips without using any Adafruit libraries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wire Master Writer | |
// by Nicholas Zambetti <http://www.zambetti.com> | |
// Demonstrates use of the Wire library | |
// Writes data to an I2C/TWI Peripheral device | |
// Refer to the "Wire Peripheral Receiver" example for use with this | |
// Created 29 March 2006 | |
// This example code is in the public domain. | |
#include <Wire.h> | |
constexpr uint8_t WIPER_ADDR = 0x28; | |
void setup() | |
{ | |
Wire.begin(); // join i2c bus (address optional for master) | |
// initialize wiper | |
constexpr uint8_t DS3502_INIT_CMD[]{0x02, 0x80}; | |
Wire.beginTransmission(WIPER_ADDR); | |
Wire.write(DS3502_INIT_CMD, sizeof(DS3502_INIT_CMD) / sizeof(DS3502_INIT_CMD[0])); | |
Wire.endTransmission() | |
} | |
void loop() | |
{ | |
static uint8_t value = 0; | |
// write actual value | |
uint8_t const DS3502_SET_CMD[]{0x00, value}; | |
Wire.beginTransmission(WIPER_ADDR); | |
Wire.write(DS3502_SET_CMD, sizeof(DS3502_SET_CMD) / sizeof(DS3502_SET_CMD[0])); | |
Wire.endTransmission(); | |
value = value < 0x7f ? value + 1 : 0; | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment