MCP3428.c 589 B

1234567891011121314151617181920212223
  1. #include "MCP3428.h"
  2. float MCP3428_Read(uint8_t channel) {
  3. Wire.beginTransmission(MCP3428_ADDRESS);
  4. Wire.write(getChannelConfigByte(channel));
  5. Wire.endTransmission();
  6. delay(200);
  7. byte config,byte1,byte2;
  8. while(1){
  9. Wire.requestFrom(MCP3428_ADDRESS, 3);
  10. byte2 = Wire.read();
  11. byte1 = Wire.read();
  12. config = Wire.read();
  13. if(config>>8==0) //tant qu'il a pas fini
  14. break;
  15. }
  16. int value = ((byte2) << 8) | byte1;
  17. Serial.print(value);
  18. return ((float)value * 62.5)/1000000;
  19. }