So I'm working on a project and I need to input specific values into a Digital Potentiometer. Here's my code:
#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 = 2; channel = 3;) {
int delaytime=100;
int level = 241;
digitalPotWrite(channel, level);
delay(delaytime);
int level = 240;
digitalPotWrite(channel, level);
delay(delaytime);
int level = 239;
digitalPotWrite(channel, level);
delay(delaytime);
int level = 238;
digitalPotWrite(channel, level);
etc, etc, etc,
}
}
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);
}
So, the problem is that the program, when I upload it gives me an error message saying that I'm redeclaring a variable and that's not allowed for some reason?
But I need to keep giving it different values, so that i can change the steps on the digital pot. Is there some way to change this so that it does what I want?
And just to let you know, that's a small sample of the program. I have 96 data points that I need to give it. The level corresponds to the steps the pot needs to go up to, to reach the required resistance value.
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.