In my quest to keep learning, I purchased a few MCP42100 digital potentiometers (Datasheet here) and have been playing around with them.
I have managed to find enough information online to get one doing what I wanted it to do. A simple script utilizing the SPI library that I modified to change the brightness of 2 LEDs. As I said, just for learning at this stage. And it works just like I wanted.
After reading some more about these chips, I learned that they can be daisy chained together and controlled by just 3 pins on the Arduino. So, this is the next step I want to figure out.
I found this interesting document, Communicating with Daisy Chained MCP42XXX Digital Potentiometers. However, it's not something I am really understanding.
Does anyone have a good reference on Shift Registers that's written in layman's terms, so to speak. Like Shift Registers for Dummies!
The following code is what I was using in conjunction with an analog potentiometer to adjust the brightness of an LED. But how one would send commands to chips on down the chain is above my head at the moment.
/* include SPI library */
#include <SPI.h>
const int slaveSelectPin = 10;
int CommandByte0 = 17;
int CommandByte1 = 18;
int value0 = 254;
int value1 = 204;
int staticPot = 0;
int a = 0;
int sensorValue = 0;
void setup() {
SPI.setClockDivider(SPI_CLOCK_DIV4);
pinMode (slaveSelectPin, OUTPUT);
SPI.begin();
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(19);
SPI.transfer(0);
digitalWrite(slaveSelectPin,HIGH);
Serial.begin(9600);
delay(10);
}
void loop(){
sensorValue = analogRead(A1);
if(sensorValue > staticPot+2 || sensorValue < staticPot-2)
{
staticPot = sensorValue;
a++;
Serial.print("a-");
Serial.print(a);
Serial.print("=");
Serial.println(sensorValue);
value0 = sensorValue/4;
changeDigiPot();
}
}
void changeDigiPot(){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(CommandByte0);
SPI.transfer(value0);
digitalWrite(slaveSelectPin,HIGH);
delay(10);
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(CommandByte1);
SPI.transfer(value1);
digitalWrite(slaveSelectPin,HIGH);
}
Any advice, links, vids, etc to help a noob out is much appreciated.