GY-63_MS5611/libraries/AD520X/examples/AD5204_demo/AD5204_demo.ino

140 lines
2.4 KiB
Arduino
Raw Normal View History

2021-01-29 06:31:58 -05:00
//
// FILE: AD5204_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2020-07-24
// URL: https://github.com/RobTillaart/AD520X
2021-10-16 14:58:54 -04:00
2021-01-29 06:31:58 -05:00
#include "AD520X.h"
uint32_t start, stop;
2021-10-16 14:58:54 -04:00
// select, reset, shutdown, data, clock
2022-10-15 13:46:24 -04:00
AD5206 pot(10, 255, 255, 8, 9); // SW SPI
// select, reset, shutdown
// AD5206 pot = AD5206(5, 6, 7); // HW SPI UNO clock = 13, data = 11
2021-01-29 06:31:58 -05:00
2021-10-16 14:58:54 -04:00
2021-01-29 06:31:58 -05:00
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
pot.begin(4);
2022-10-15 13:46:24 -04:00
// test_extremes();
// test_sinus();
// test_sawtooth();
2021-01-29 06:31:58 -05:00
test_timing();
Serial.println("\nDone...");
}
2021-10-16 14:58:54 -04:00
2021-01-29 06:31:58 -05:00
void loop()
{
}
2022-10-15 13:46:24 -04:00
void test_extremes()
{
Serial.println(__FUNCTION__);
delay(10);
Serial.println("0");
pot.setValue(0, 0);
delay(2000);
Serial.println("127");
pot.setValue(0, 127);
delay(2000);
Serial.println("255");
pot.setValue(0, 255);
delay(2000);
}
2021-10-16 14:58:54 -04:00
// connect all A GND and B 5V
// every W will have a different signal (same freq).
2021-01-29 06:31:58 -05:00
void test_sinus()
{
Serial.println(__FUNCTION__);
delay(10);
start = millis();
uint32_t i = 0;
while (millis() - start < 10000)
{
2022-10-15 13:46:24 -04:00
int8_t value = 127 * sin(i * TWO_PI / 100);
2021-01-29 06:31:58 -05:00
pot.setValue(0, 128 + value);
pot.setValue(1, 128 + value / 2);
pot.setValue(2, 64 + value / 2);
pot.setValue(3, 192 + value / 2);
pot.setValue(4, 224 + value / 4);
pot.setValue(5, 128 - value);
i++;
}
}
2021-10-16 14:58:54 -04:00
// straightforward sawtooth.
2021-01-29 06:31:58 -05:00
void test_sawtooth()
{
Serial.println(__FUNCTION__);
delay(10);
start = millis();
uint8_t i = 0;
2022-10-15 13:46:24 -04:00
while (millis() - start < 25500)
2021-01-29 06:31:58 -05:00
{
2021-10-16 14:58:54 -04:00
pot.setValue(0, i++); // auto wrap is fast...
2022-10-15 13:46:24 -04:00
delay(100);
2021-01-29 06:31:58 -05:00
}
}
2021-10-16 14:58:54 -04:00
2021-01-29 06:31:58 -05:00
void test_timing()
{
Serial.println(__FUNCTION__);
delay(10);
start = micros();
for (int i = 0; i < 10000; i++)
{
2021-10-16 14:58:54 -04:00
pot.setValue(0, i++); // auto wrap is fast...
2021-01-29 06:31:58 -05:00
}
stop = micros();
Serial.print("10000 x setValue():\t");
Serial.println(stop - start);
delay(10);
start = micros();
for (int i = 0; i < 1000; i++)
{
pot.setAll(i++);
}
stop = micros();
Serial.print("1000 x setAll():\t");
Serial.println(stop - start);
delay(10);
volatile int x = 0;
start = micros();
for (int i = 0; i < 250; i++)
{
x += pot.getValue(0);
x += pot.getValue(1);
x += pot.getValue(2);
x += pot.getValue(3);
}
stop = micros();
Serial.print("1000 x getValue():\t");
Serial.println(stop - start);
delay(10);
}
2021-10-16 14:58:54 -04:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --