adding Arduino and CP examples for ADG72x
This commit is contained in:
parent
738b887bf8
commit
297910abbf
2 changed files with 83 additions and 0 deletions
|
|
@ -0,0 +1,58 @@
|
|||
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <Adafruit_ADG72x.h>
|
||||
|
||||
Adafruit_ADG72x adg72x;
|
||||
|
||||
bool isADG728 = false; // which chip are we connected to?
|
||||
|
||||
int analogIn = A0;
|
||||
int analogValue = 0;
|
||||
unsigned long timer = 2000;
|
||||
unsigned long startTime = millis();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Wait for serial port to open
|
||||
while (!Serial) {
|
||||
delay(1);
|
||||
}
|
||||
|
||||
// Try with the ADG728 default address first...
|
||||
if (adg72x.begin(ADG728_DEFAULT_ADDR, &Wire)) {
|
||||
Serial.println("ADG728 found!");
|
||||
isADG728 = true;
|
||||
}
|
||||
// Maybe they have an ADG729?
|
||||
else if (adg72x.begin(ADG729_DEFAULT_ADDR, &Wire)) {
|
||||
Serial.println("ADG729 found!");
|
||||
isADG728 = false;
|
||||
}
|
||||
else {
|
||||
Serial.println("No ADG device found? Check wiring!");
|
||||
while (1); // Stop here if no device was found
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
analogValue = analogRead(analogIn);
|
||||
Serial.println(analogValue);
|
||||
|
||||
if ((millis() - startTime) >= timer) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
if (isADG728) {
|
||||
} else {
|
||||
if (i < 4) Serial.println("A");
|
||||
else Serial.println("B");
|
||||
}
|
||||
uint8_t bits = 1 << i; // Shift a '1' from LSB to MSB
|
||||
if (!adg72x.selectChannels(bits)) {
|
||||
}
|
||||
startTime = millis();
|
||||
}
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
25
ADG72x_Examples/CircuitPython/code.py
Normal file
25
ADG72x_Examples/CircuitPython/code.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2024 Liz Clark for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import time
|
||||
import board
|
||||
import adafruit_adg72x
|
||||
from analogio import AnalogIn
|
||||
|
||||
analog_in = AnalogIn(board.A0)
|
||||
|
||||
i2c = board.I2C()
|
||||
switch = adafruit_adg72x.ADG72x(i2c)
|
||||
|
||||
c = 0
|
||||
switch_time = 2
|
||||
clock = time.monotonic()
|
||||
while True:
|
||||
if (time.monotonic() - clock) > switch_time:
|
||||
print(f"Selecting channel {c + 1}")
|
||||
switch.channel = c
|
||||
c = (c + 1) % 8
|
||||
clock = time.monotonic()
|
||||
print((analog_in.value,))
|
||||
time.sleep(0.1)
|
||||
Loading…
Reference in a new issue