| 12345678910111213141516171819202122232425262728293031323334 |
- from robot_control.src.api.i2c_handler import I2C
- from robot_control.src.vendor.mcp3428 import MCP3428
- from time import sleep
- import asyncio
- async def main():
- # Initialize with multiple channels (1 through 4)
- i2c = I2C(device_class=MCP3428, gain=1, resolution=12)
- i2c.initialize()
- counter = 0
- while True:
- # Read channel 4 every iteration
- selection = [4]
- # Read channel 3 every 4 seconds
- if counter % 4 == 0:
- selection.append(3)
- # Read channel 1 every 10 iterations
- if counter % 10 == 0:
- selection.append(1)
- readings = await i2c.read_channels(selection)
- for channel, value in readings.items():
- print(f"Channel {channel}: {value}")
- counter += 1
- await asyncio.sleep(1)
- if __name__ == "__main__":
- asyncio.run(main())
|