No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

72 líneas
1.9KB

  1. /*
  2. Digital Pot Control
  3. This example controls an Analog Devices AD5206 digital potentiometer.
  4. The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
  5. A - connect this to voltage
  6. W - this is the pot's wiper, which changes when you set it
  7. B - connect this to ground.
  8. The AD5206 is SPI-compatible,and to command it, you send two bytes,
  9. one with the channel number (0 - 5) and one with the resistance value for the
  10. channel (0 - 255).
  11. The circuit:
  12. * All A pins of AD5206 connected to +5V
  13. * All B pins of AD5206 connected to ground
  14. * An LED and a 220-ohm resisor in series connected from each W pin to ground
  15. * CS - to digital pin 10 (SS pin)
  16. * SDI - to digital pin 11 (MOSI pin)
  17. * CLK - to digital pin 13 (SCK pin)
  18. created 10 Aug 2010
  19. by Tom Igoe
  20. Thanks to Heather Dewey-Hagborg for the original tutorial, 2005
  21. */
  22. // inslude the SPI library:
  23. #include <SPI.h>
  24. // set pin 10 as the slave select for the digital pot:
  25. const int slaveSelectPin = 10;
  26. void setup() {
  27. // set the slaveSelectPin as an output:
  28. pinMode (slaveSelectPin, OUTPUT);
  29. // initialize SPI:
  30. SPI.begin();
  31. }
  32. void loop() {
  33. // go through the six channels of the digital pot:
  34. for (int channel = 0; channel < 6; channel++) {
  35. // change the resistance on this channel from min to max:
  36. for (int level = 0; level < 255; level++) {
  37. digitalPotWrite(channel, level);
  38. delay(10);
  39. }
  40. // wait a second at the top:
  41. delay(100);
  42. // change the resistance on this channel from max to min:
  43. for (int level = 0; level < 255; level++) {
  44. digitalPotWrite(channel, 255 - level);
  45. delay(10);
  46. }
  47. }
  48. }
  49. void digitalPotWrite(int address, int value) {
  50. // take the SS pin low to select the chip:
  51. digitalWrite(slaveSelectPin,LOW);
  52. // send in the address and value via SPI:
  53. SPI.transfer(address);
  54. SPI.transfer(value);
  55. // take the SS pin high to de-select the chip:
  56. digitalWrite(slaveSelectPin,HIGH);
  57. }