I have this in the header file
/**
* @file x9cxx.h
* @brief digital pot functions
*/
#ifndef x9cxx_H
#define x9cxx_H
// POT PINS
#define POT_SELECT 6
#define INC 1
#define UD 5
// Pot FUNCTIONS
#define UP 1
#define DOWN 0
#define SELECT 0
#define UNSELECT 1
void setPot (uint requestedSpeed);
void resetPot (void);
void calcPulses (char val[],uint current, uint requested);
#endif // #ifndef x9cxx_H
And this bit is the code I used. Not all the variables are define in this piece of code but yoy should be able to see how it is done. Very easy really.
void setPot (uint requestedSpeed)
{
char val[2];
calcPulses(val,config.motorSpeed, requestedSpeed);
digitalWrite(INC,HIGH);
digitalWrite(POT_SELECT,SELECT);
digitalWrite(UD,val[1]);
for(char i=1;i<val[0];i++)
{
digitalWrite(INC, HIGH); // sets the pin on
delayMicroseconds(5000); // pauses for 50 microseconds
digitalWrite(INC, LOW); // sets the pin off
delayMicroseconds(5000); // pauses for 50 microseconds
}
digitalWrite(INC,HIGH);
digitalWrite(POT_SELECT,HIGH);
delay(20);
}
void resetPot (void)
{
pinMode(INC,OUTPUT);
pinMode(POT_SELECT,OUTPUT);
pinMode(UD,OUTPUT);
digitalWrite(INC,HIGH);
digitalWrite(POT_SELECT,SELECT);
digitalWrite(UD,DOWN);
for(char i=0;i<100;i++)
{
digitalWrite(INC, HIGH); // sets the pin on
delayMicroseconds(5000); // pauses for 50 microseconds
digitalWrite(INC, LOW); // sets the pin off
delayMicroseconds(5000); // pauses for 50 microseconds
}
digitalWrite(INC,HIGH);
digitalWrite(POT_SELECT,HIGH);
delay(20);
}
void calcPulses (char val[],uint current, uint requested)
{
//char val[2];
char RpmPp = config.maxSpeed / 100;
if(current < requested)
{
val[0] = (requested - current)/RpmPp;
val[1] = UP;
}else
if(current > requested)
{
val[0] = (current - requested)/RpmPp;
val[1] = DOWN;
}
}