53 ThreeDifferential = 0x10,
54 SingleAndDifferential = 0x20,
55 TwoDifferential = 0x30
58 static const uint8_t DEFAULT_DEVICE_ADDRESS = 0x90;
59 static const uint8_t DAC_ENABLE = BIT_6;
60 static const uint8_t CHANNEL_BITS = BIT_1 | BIT_0;
71 PCF8591 (
const uint8_t deviceAddress = DEFAULT_DEVICE_ADDRESS,
const I2C *i2cBus = &
pwI2c)
73 m_deviceAddress(deviceAddress),
83 return this->m_i2c->
ping(this->m_deviceAddress);
97 this->m_i2c->
get(this->m_deviceAddress, buffer,
sizeof(buffer));
98 return buffer[
sizeof(buffer) - 1];
112 return this->m_i2c->
get(this->m_deviceAddress, data, 1);
124 return this->m_i2c->
get(this->m_deviceAddress, data, size);
135 this->m_currentProgram &= ~CHANNEL_BITS;
136 this->m_currentProgram |= channel;
137 return this->program();
150 this->m_currentProgram |= AUTO_INC_ON;
152 this->m_currentProgram &= ~AUTO_INC_ON;
153 return this->program();
164 this->m_currentProgram &= ~0x30;
165 this->m_currentProgram |= mode;
166 return this->program();
175 this->m_currentProgram |= DAC_ENABLE;
176 return this->program();
185 this->m_currentProgram &= ~DAC_ENABLE;
186 return this->program();
196 bool write (
const uint8_t dacValue) {
197 this->m_currentProgram |= DAC_ENABLE;
198 return this->m_i2c->
put(this->m_deviceAddress, this->m_currentProgram, dacValue);
210 this->m_currentProgram |= DAC_ENABLE;
211 return this->m_i2c->
put(this->m_deviceAddress, this->m_currentProgram, dacValues, size);
215 bool program ()
const {
216 return this->m_i2c->
put(this->m_deviceAddress, this->m_currentProgram);
221 const uint8_t m_deviceAddress;
223 uint8_t m_currentProgram;
Generic definitions and functions for the Parallax Propeller.
bool set_auto_increment(const bool autoIncrement)
When enabled, auto increment will change to the next ADC channel with every query. This is normally off.
A simple 4-channel, 8-bit ADC and single-channel 8-bit DAC both integrated into one chip...
bool read_multi(uint8_t data[], const size_t size) const
Get multiple sequential readings from the same channel.
bool write_multi(const uint8_t dacValues[], const size_t size)
Write a series of values to the DAC sequentially.
bool enable_dac()
Begin outputting the current value out the DAC line.
bool disable_dac()
Turn off the DAC.
bool ping() const
Ensure the device is responding on the I2C bus.
bool write(const uint8_t dacValue)
Set the current value for the DAC.
bool ping(const uint8_t device) const
Test for the Acknowledge of a device by sending start and the slave address.
uint8_t get(const uint8_t device, const T address) const
Get a single byte with the following format:
PropWare::I2C pwI2c
Global I2C instance for easy and shared use by Propeller applications (not thread safe!) ...
bool put(const uint8_t device, const T address, const uint8_t byte) const
Put a single byte with the following format:
uint8_t read_channel(const ADCChannel channel)
Read the ADC value from a given channel.
bool read_next(uint8_t *data) const
Retrieve the next ADC value for the previously set channel.
bool set_read_mode(const ReadMode mode)
Switch between the different modes for the ADC.
bool set_channel(const ADCChannel channel)
Use the given channel for subsequent queries.
PCF8591(const uint8_t deviceAddress=DEFAULT_DEVICE_ADDRESS, const I2C *i2cBus=&pwI2c)
Constructor.