AD5242.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. byte AD_adress1 = 0x2c;
  7. byte AD_adress2 = 0x2f;
  8. byte AD_pot1 = 0x00;
  9. byte AD_pot2 = 0x80;
  10. int potValue[4];
  11. int potValueUpdate[4];
  12. byte potAdress[4][2] = { {AD_adress1, AD_pot1},
  13. {AD_adress1, AD_pot2},
  14. {AD_adress2, AD_pot1},
  15. {AD_adress2, AD_pot2}, };
  16. void setup_AD5242() {
  17. Wire.begin(); // join i2c bus (address optional for master)
  18. Serial.println("starting digipots");
  19. Serial.println(AD_adress1);
  20. Serial.println(AD_pot1);
  21. Serial.println(potAdress[0][0]);
  22. for (int i ; i<4 ; i++) {
  23. for (int j ; j<2 ; j++){
  24. Serial.print (potAdress[i][j], HEX);
  25. Serial.print ("-");
  26. }
  27. }
  28. }
  29. void handle_AD5242() {
  30. for (int pot ; pot<4 ; pot++){
  31. // Serial.println("pot");
  32. // Serial.print(potAdress[pot][0] + " : ");
  33. // Serial.println(potAdress[pot][1]);
  34. if (potValue[pot] != potValueUpdate[pot]) {
  35. potValue[pot] = potValueUpdate[pot];
  36. Wire.beginTransmission(potAdress[pot][0]);
  37. Wire.write(potAdress[pot][1]);
  38. Wire.write(potValue[pot]);
  39. Wire.endTransmission();
  40. Serial.println("updated");
  41. }
  42. }
  43. }