output
pot 526, spd 0, dly 0, dir 0 Stop
pot 526, spd 0, dly 0, dir 0 Stop
pot 514, spd 0, dly 0, dir 0 Stop
pot 495, spd -1, dly 1000, dir -1 Rev
pot 481, spd -1, dly 1000, dir -1 Rev
pot 473, spd -1, dly 1000, dir -1 Rev
pot 494, spd -1, dly 1000, dir -1 Rev
pot 512, spd 0, dly 0, dir 0 Stop
pot 531, spd 0, dly 0, dir 0 Stop
pot 551, spd 0, dly 0, dir 0 Stop
pot 575, spd 1, dly 1000, dir 1 For
pot 590, spd 1, dly 1000, dir 1 For
pot 609, spd 1, dly 1000, dir 1 For
pot 635, spd 2, dly 500, dir 1 For
pot 656, spd 2, dly 500, dir 1 For
pot 680, spd 3, dly 333, dir 1 For
pot 701, spd 3, dly 333, dir 1 For
pot 718, spd 4, dly 250, dir 1 For
pot 739, spd 4, dly 250, dir 1 For
pot 749, spd 4, dly 250, dir 1 For
// speed control pot
const int PotMax = 1023;
const int SpdMax = 10;
char s [90];
// -----------------------------------------------------------------------------
void
loop ()
{
int pot = analogRead (A0);
int spd = map(pot, 0, PotMax, -SpdMax, SpdMax);
int dly = spd == 0 ? 0 : 1000/abs(spd);
int dir = spd == 0 ? 0 : (spd > 0 ? 1 : -1);
sprintf (s, " pot %6d, spd %6d, dly %6d, dir %2d %s",
pot, spd, dly, dir, dir == 0 ? "Stop" : (dir > 0 ? "For" : "Rev") );
Serial.println (s);
delay (1500); // slow prints
}
// -----------------------------------------------------------------------------
void
setup (void)
{
Serial.begin (9600);
}