GY-63_MS5611/libraries/PCF8591/examples/PCF8591_demo/PCF8591_demo.ino

84 lines
1.4 KiB
Arduino
Raw Normal View History

2021-01-29 06:31:58 -05:00
//
// FILE: PCF8591_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2020-07-22
// URL: https://github.com/RobTillaart/PCF8591
2021-12-23 08:26:13 -05:00
2021-01-29 06:31:58 -05:00
#include "PCF8591.h"
PCF8591 dev(0x48);
2021-12-23 08:26:13 -05:00
2021-01-29 06:31:58 -05:00
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Wire.begin();
Wire.setClock(100000UL);
#if defined (ESP8266) || defined(ESP32)
dev.begin(21, 22);
#endif
dev.begin();
}
2021-12-23 08:26:13 -05:00
2021-01-29 06:31:58 -05:00
void loop()
{
test_DAC();
delay(1000);
test_ADC_mode(0);
delay(1000);
// differential modes, check datasheet
test_ADC_mode(1);
delay(1000);
test_ADC_mode(2);
delay(1000);
test_ADC_mode(3);
delay(1000);
}
void test_DAC()
{
Serial.println(__FUNCTION__);
Serial.println("--------------");
dev.enableDAC();
for (int i = 0; i < 5000; i++)
{
uint8_t val = 127 + 127 * sin(i * 0.01);
Serial.println(val);
dev.analogWrite(val);
delay(1); // just to slow the effect
}
dev.disableDAC();
Serial.println();
}
2021-12-23 08:26:13 -05:00
2021-01-29 06:31:58 -05:00
void test_ADC_mode(uint8_t mode)
{
uint8_t channels[] = {4, 3, 3, 2 }; // channels per mode
Serial.println(__FUNCTION__);
Serial.println("--------------");
Serial.println("CH0\tCH1\tCH2\tCH3");
for (int m = 0; m < 20; m++)
{
for (uint8_t i = 0; i < channels[mode]; i++)
{
Serial.print(dev.analogRead(i, mode));
Serial.print('\t');
}
Serial.println();
}
Serial.println();
}
2021-12-23 08:26:13 -05:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2021-12-23 08:26:13 -05:00