aboutsummaryrefslogtreecommitdiff
path: root/msp430/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino
diff options
context:
space:
mode:
authorDonald Delmar Davis <don@suspectdevices.com>2012-10-03 11:01:38 -0700
committerDonald Delmar Davis <don@suspectdevices.com>2012-10-03 11:01:38 -0700
commit1368288178e48ba6164e8623ea85046e59041932 (patch)
treee82fcb8607d14e2fc459a5d00a7e2dab50e6221d /msp430/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino
parentaea305de919855fd68a9654830382360ad6a22b5 (diff)
move csource and core into place
Diffstat (limited to 'msp430/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino')
-rw-r--r--msp430/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino73
1 files changed, 73 insertions, 0 deletions
diff --git a/msp430/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/msp430/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino
new file mode 100644
index 0000000..d808a68
--- /dev/null
+++ b/msp430/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino
@@ -0,0 +1,73 @@
+/*
+ Digital Pot Control
+
+ This example controls an Analog Devices AD5206 digital potentiometer.
+ The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
+ A - connect this to voltage
+ W - this is the pot's wiper, which changes when you set it
+ B - connect this to ground.
+
+ The AD5206 is SPI-compatible,and to command it, you send two bytes,
+ one with the channel number (0 - 5) and one with the resistance value for the
+ channel (0 - 255).
+
+ The circuit:
+ * All A pins of AD5206 connected to +5V
+ * All B pins of AD5206 connected to ground
+ * An LED and a 220-ohm resisor in series connected from each W pin to ground
+ * CS - to digital pin 8 (SS pin) P2.0
+ * SDI - to digital pin 14/15 (MOSI pin USI/USCI) P1.6/P1.7
+ * CLK - to digital pin 7 (SCK pin) P1.5
+
+ created 10 Aug 2010
+ by Tom Igoe
+
+ modified 2 May 2012 - changed SS pin
+ by Rick Kimball
+
+ Thanks to Heather Dewey-Hagborg for the original tutorial, 2005
+
+*/
+
+
+// include the SPI library:
+#include <SPI.h>
+
+// set pin 8 as the slave select for the digital pot:
+const int slaveSelectPin = SS;
+
+void setup() {
+ // set the slaveSelectPin as an output:
+ pinMode (slaveSelectPin, OUTPUT);
+ // initialize SPI:
+ SPI.begin();
+}
+
+void loop() {
+ // go through the six channels of the digital pot:
+ for (int channel = 0; channel < 6; channel++) {
+ // change the resistance on this channel from min to max:
+ for (int level = 0; level < 255; level++) {
+ digitalPotWrite(channel, level);
+ delay(10);
+ }
+ // wait a second at the top:
+ delay(100);
+ // change the resistance on this channel from max to min:
+ for (int level = 0; level < 255; level++) {
+ digitalPotWrite(channel, 255 - level);
+ delay(10);
+ }
+ }
+
+}
+
+int digitalPotWrite(int address, int value) {
+ // take the SS pin low to select the chip:
+ digitalWrite(slaveSelectPin,LOW);
+ // send in the address and value via SPI:
+ SPI.transfer(address);
+ SPI.transfer(value);
+ // take the SS pin high to de-select the chip:
+ digitalWrite(slaveSelectPin,HIGH);
+} \ No newline at end of file