I have a digital rheostat 10 kOhm potentiometer, that I want ultimately to control the volume of a radio, but for now, just want to fade an LED.
I have it fading in/ almost out, except I cannot make the LED turn of entirely.
I've been reading about the differences between rheostat and potentiometers - and many people mention different things, so I'm kind of confused. Also - i thought I ordered a digital potentiometer, but by accident bought a rheostat. soo.. is it even possible to make a rheostat "turn off" entirely?
I have attached a schematic of the setup, and the code:
link to digi pot datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf
BREADBOARD:
SCHEMATICS:
ARDUINO CODE:
#include <SPI.h>
int ss = 10; // slave select pins
void setup() {
// set SS pin directions
// Others are handled automatically
pinMode(ss, OUTPUT);
//Initialize SPI
SPI.begin();
Serial.begin(9600);
}
// function to set LED to specific level
// reg is the register, register is the index - this is only one pot,
// so the reg is == 00000000
// level is the leve
void setLed(int reg, int level) {
digitalWrite(ss, LOW); // set SS to low for communicating to that chip
SPI.transfer(reg); // send register / index
SPI.transfer(level);
digitalWrite(ss, HIGH); // Finish writing to that chip
}
void loop() {
for(int i = 0; i<255; i++) {
setLed(0, i);
delay(20);
Serial.println(i);
}
delay(500);
for(int i = 255; i >= 0; i--) {
setLed(0, i);
delay(20);
Serial.println(i);
}
delay(500);
}