Hey I was wondering how to make my LED lights dim. They are 2 of the six on but they do not dim or turn on and off after I modified the code. I got the code from the arduino website and it does not work. The code is at the bottom of the page. http://arduino.cc/en/Tutorial/SPIDigitalPot
but they do not dim or turn on and off after I modified the code.
Where's the code?
Edit: cross-posting is a fast-track to forum banning, but don't worry, I've deleted your duplicate post.
If you want to dim an LED in order to demonstrate or sanity check the use of a digipot, that is fine, but it is not the preferred way of dimming an LED for a real project. It's both overkill and a waste of energy. PWM is the preferred way to do it, just vary the duty cycle through the analog channel. You can use this is a signal into a transistor or MOSFET and put dimmable control over a large number of LEDs this way.
The code is on the website that I posted with the comment.
/*
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 10 (SS pin)
- SDI - to digital pin 11 (MOSI pin)
- CLK - to digital pin 13 (SCK pin)
created 10 Aug 2010
by Tom Igoe
Thanks to Heather Dewey-Hagborg for the original tutorial, 2005
*/
// inslude the SPI library:
#include <SPI.h>
// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
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);
}
}
}
void 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);
}
I'm creating a project that needs a digital potentiometer to control a motor control. In order to do that I’m testing the digital potentiometer with the LED lights just as the website tells me to do so see if the digital pot is working.
You say you modified the code.... so is the code you just posted the original or the new one with your mods? What changes did you make and in what way does it not work? Did it work before you made any changes?
kaceves:
I'm creating a project that needs a digital potentiometer to control a motor control. In order to do that I’m testing the digital potentiometer with the LED lights just as the website tells me to do so see if the digital pot is working.
From the datasheet depending on what resistance range your chip is using you probably can't drive leds as the current limit for the chip resistor outputs are probably exceeded. Test your digital resistor outputs with a voltmeter to determine if your code is correct or not, not current drawing leds.
A, IB, IW
Pulsed ±20 mA
Continuous 10 k? End-to-End Resistance ±11 mA
50 k? and 100 k? End-to-End Resistance ±2.5 mA
Lefty
Yes thats the original code and it still does not work.
My resistance is good because I already checked with the voltmeter and the lights do not dim