AD5242.h 827 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <Wire.h>
  2. #define AD_adress1 0x2c
  3. #define AD_adress2 0x2f
  4. #define AD_pot1 0x00
  5. #define AD_pot2 0x80
  6. int potValue[4];
  7. int potValueUpdate[4];
  8. byte potAdress[][2] = { {AD_adress1, AD_pot1},
  9. {AD_adress1, AD_pot2},
  10. {AD_adress2, AD_pot1},
  11. {AD_adress2, AD_pot2}, };
  12. void setup_AD5242() {
  13. Wire.begin(); // join i2c bus (address optional for master)
  14. Serial.begin(115200);
  15. }
  16. void handle_AD5242() {
  17. for (int i ; i++ ; i<4){
  18. if (potValue[i] != potValueUpdate[i]) {
  19. potValue[i] = potValueUpdate[i];
  20. Wire.beginTransmission(potAdress[i][1]);
  21. Wire.write(potAdress[i][2]);
  22. Wire.write(potValue[i]);
  23. Wire.endTransmission();
  24. Serial.print(potAdress[i][1] + " : ");
  25. Serial.println(potAdress[i][2]);
  26. }
  27. }
  28. }