consider the following.
Not sure how you plan on using a single pot. Assume you want to use the pot to change the rate a waveform runs at
// -----------------------------------------------------------------------------
byte sine [] = {
128, 131, 134, 137, 140, 143, 146, 149,
152, 156, 159, 162, 165, 168, 171, 174,
176, 179, 182, 185, 188, 191, 193, 196,
199, 201, 204, 206, 209, 211, 213, 216,
218, 220, 222, 224, 226, 228, 230, 232,
234, 236, 237, 239, 240, 242, 243, 245,
246, 247, 248, 249, 250, 251, 252, 252,
253, 254, 254, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 254, 254,
253, 252, 252, 251, 250, 249, 248, 247,
246, 245, 243, 242, 240, 239, 237, 236,
234, 232, 230, 228, 226, 224, 222, 220,
218, 216, 213, 211, 209, 206, 204, 201,
199, 196, 193, 191, 188, 185, 182, 179,
176, 174, 171, 168, 165, 162, 159, 156,
152, 149, 146, 143, 140, 137, 134, 131,
128, 124, 121, 118, 115, 112, 109, 106,
103, 99, 96, 93, 90, 87, 84, 81,
79, 76, 73, 70, 67, 64, 62, 59,
56, 54, 51, 49, 46, 44, 42, 39,
37, 35, 33, 31, 29, 27, 25, 23,
21, 19, 18, 16, 15, 13, 12, 10,
9, 8, 7, 6, 5, 4, 3, 3,
2, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1,
2, 3, 3, 4, 5, 6, 7, 8,
9, 10, 12, 13, 15, 16, 18, 19,
21, 23, 25, 27, 29, 31, 33, 35,
37, 39, 42, 44, 46, 49, 51, 54,
56, 59, 62, 64, 67, 70, 73, 76,
79, 81, 84, 87, 90, 93, 96, 99,
103, 106, 109, 112, 115, 118, 121, 124,
};
byte tri [] = {
0, 2, 4, 6, 8, 10, 12, 14,
16, 18, 20, 22, 24, 26, 28, 30,
32, 34, 36, 38, 40, 42, 44, 46,
48, 50, 52, 54, 56, 58, 60, 62,
64, 66, 68, 70, 72, 74, 76, 78,
80, 82, 84, 86, 88, 90, 92, 94,
96, 98, 100, 102, 104, 106, 108, 110,
112, 114, 116, 118, 120, 122, 124, 126,
128, 130, 132, 134, 136, 138, 140, 142,
144, 146, 148, 150, 152, 154, 156, 158,
160, 162, 164, 166, 168, 170, 172, 174,
176, 178, 180, 182, 184, 186, 188, 190,
192, 194, 196, 198, 200, 202, 204, 206,
208, 210, 212, 214, 216, 218, 220, 222,
224, 226, 228, 230, 232, 234, 236, 238,
240, 242, 244, 246, 248, 250, 252, 254,
254, 252, 250, 248, 246, 244, 242, 240,
238, 236, 234, 232, 230, 228, 226, 224,
222, 220, 218, 216, 214, 212, 210, 208,
206, 204, 202, 200, 198, 196, 194, 192,
190, 188, 186, 184, 182, 180, 178, 176,
174, 172, 170, 168, 166, 164, 162, 160,
158, 156, 154, 152, 150, 148, 146, 144,
142, 140, 138, 136, 134, 132, 130, 128,
126, 124, 122, 120, 118, 116, 114, 112,
110, 108, 106, 104, 102, 100, 98, 96,
94, 92, 90, 88, 86, 84, 82, 80,
78, 76, 74, 72, 70, 68, 66, 64,
62, 60, 58, 56, 54, 52, 50, 48,
46, 44, 42, 40, 38, 36, 34, 32,
30, 28, 26, 24, 22, 20, 18, 16,
14, 12, 10, 8, 6, 4, 2, 0,
};
byte sq [] = {
0, 255
};
// -----------------------------------------------------------------------------
enum { LED10 = 10, LED11, LED12, LED13 };
byte buts [] = { A1, A2, A3 };
byte leds [] = { LED10, LED11, LED12, LED13 };
struct LedWave_s {
byte led;
byte *wave;
int size;
unsigned long msecDwell;
unsigned long msecLst;
int idx;
};
LedWave_s ledWave [] = {
{ LED10, sine, sizeof(sine), 10 },
{ LED11, tri, sizeof(tri), 20 },
{ LED12, sq, sizeof(sq), 500 },
};
#define N_LEDWAVE (sizeof(ledWave)/sizeof(LedWave_s))
unsigned long msec;
// ---------------------------------------------------------
void
wave (
LedWave_s *w)
{
if (msec - w->msecLst > w->msecDwell) {
w->msecLst = msec;
analogWrite (w->led, w->wave [w->idx]);
w->idx = w->idx < (w->size - 1) ? w->idx + 1 : 0;
#if 0
char s [80];
sprintf (s, "wave: pin %d, idx %d, val %3d",
w->led, w->idx, w->wave [w->idx]);
Serial.println (s);
#endif
}
}
// -----------------------------------------------------------------------------
void
loop (void)
{
msec = millis ();
LedWave_s *w = ledWave;
for (unsigned n = 0; n < N_LEDWAVE; n++, w++)
wave (w);
}
// ---------------------------------------------------------
void
setup (void)
{
Serial.begin (115200);
for (unsigned i =0; i < sizeof(buts); i++)
pinMode (buts [i], INPUT_PULLUP);
for (unsigned i =0; i < sizeof(leds); i++) {
pinMode (leds [i], OUTPUT);
digitalWrite (leds [i], HIGH);
}
}