Problem with programming an Arduino Uno

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.

chad_carlson:
So I’m working on a project and I need to input specific values into a Digital Potentiometer. Here’s my code:

Please use code tags.

void loop() {
  // go through the six channels of the digital pot:
  for (int channel = 2; channel = 3;) {

This is a problem, as it will loop forever. On the first loop, channel will be 2, and all remaining loops channel will be 3. You never increment channel, and instead of testing channel against 3, you reset it to 3. I believe you wanted:

  for (int channel = 2; channel <= 3; channel++) {
    int delaytime=100;
    int level = 241; 
    digitalPotWrite(channel, level);
    delay(delaytime);
    int level = 240;

This is what the compiler is complaining about. You don’t want the second ‘int’. Instead you just want to assign the new value.

Here is what I think you want:

void loop() {
  // go through the six channels of the digital pot:
  for (int channel = 2; channel <= 3; channel++) {
    int delaytime=100;
    int level = 241; 
    digitalPotWrite(channel, level);
    delay(delaytime);
    level = 240; 
    digitalPotWrite(channel, level);
    delay(delaytime);
    level = 239; 
    digitalPotWrite(channel, level);
    delay(delaytime);
    level = 238; 
    digitalPotWrite(channel, level);
    // etc, etc, etc, 
  }
}

If the only place you are using level is in the digitalPotWrite, you could eliminate the variable all together. I’m not a fan of ‘magic’ constants like this, but some times it works:

void loop() {
  // go through the six channels of the digital pot:
  for (int channel = 2; channel <= 3; channel++) {
    int delaytime=100;
    digitalPotWrite(channel, 241);
    delay(delaytime);
    digitalPotWrite(channel, 240);
    delay(delaytime);
    digitalPotWrite(channel, 239);
    delay(delaytime);
    digitalPotWrite(channel, 238);
    // etc, etc, etc, 
  }
}

Given you are going through the values in reverse order, the following would be a simpler way to do it (be sure to notice that in that case, I used greater than or equal ‘>=’ instead of less than or equal ‘<=’):

void loop() {
  // go through the six channels of the digital pot:
  for (int channel = 2; channel <= 3; channel++) {
    int delaytime=100;
    for (int level = 241; level >= 239; level--) {
      digitalPotWrite(channel, level);
      delay(delaytime);
    }
    level--;
    digitalPotWrite(channel, level);
    // etc, etc, etc, 
  }
}

Note, if you needed a final delay, you could have eliminated the last digitalPotWrite:

void loop() {
  // go through the six channels of the digital pot:
  for (int channel = 2; channel <= 3; channel++) {
    int delaytime=100;
    for (int level = 241; level >= 238; level--) {
      digitalPotWrite(channel, level);
      delay(delaytime);
   }
    // etc, etc, etc, 
  }
}

You probably need to study the various C++ tutorials to better learn the language.

Okay, the program works now. Thanks. The part about getting rid of all the ints except the first one is what did the trick.
The rest was unnecessary, but that's more my fault for not being clear.

My program runs through a set of values. And it's completely non-linear. So the (level --) part doesn't work for that. I wish it did, as that would be far less tedious than what I had to do.

To clarify, the program starts at 241, goes all the way down to 120, then fluctuates between 120 and 140 for about 50 data points. Then it goes all the way back up to 250. It's more like a horseshoe shape when you plot it. The "etc, etc, etc" was put there because I didn't want to put an extra 90 lines of code into my post.