I am trying to get one of the two digital potentiometers in the MCP4231 IC to operate a green LED. The Arduino code should cycle the green LED from off to full on, then cycle the green LED to off. This program should loop the code making the Green LED go off and on.
I did not hook up any wires to the second potentiometer in the MCP4231 IC.
I am not getting anything out of the green LED, it never comes on. The code runs and there are no errors. I have checked my wiring connections several times. I think something in the code is making it not work.
One question I do have is this: The MCP4231 IC has a MOSI connection and a MISO connection. I have tried with the MISO connected and not connected and the green LED will not light either way. I notice on the MCP4131 IC---the single version of the MCP4231 they do not connect to the MISO when controlling a LED in the same way.
Below is my code, something is wrong because it does not work, and there are no error messages.
byte addressGreenLED=B00000000;
int CS=10;
void setup()
{
pinMode (CS,OUTPUT); // put your setup code here, to run once:
SPI.begin();
}
void loop()
{
for(int j = 0; j <=128; j++) // put your main code here, to run repeatedly:
{
digitalPotWriteGreen(j);
delay(100);
}
delay(2000);
for (int j = 128; j >= 0; j--)
{
digitalPotWriteGreen(j);
delay(100);
}
delay (2000);
}
int digitalPotWriteGreen(int valueGreen)
{digitalWrite(CS,LOW);
SPI.transfer(addressGreenLED);
SPI.transfer(valueGreen);
digitalWrite(CS,HIGH);
}