# How to build a code of time-shifting function generator?

I'm going to make a cymatic device with Arduino Due which makes time-shiftnig patterns.

So I made a source code from the copy of this,

and a cord I made is this.

``````/*
Simple Waveform generator with Arduino Due

* connect two push buttons to the digital pins 2 and 3
with a 10 kilohm pulldown resistor to choose the waveform
to send to the DAC0 and DAC1 channels
* connect a 10 kilohm potentiometer to A0 to control the
signal frequency

*/

#include "Waveforms.h"

#define oneHzSample 1000000/maxSamplesNum  // sample for the 1Hz signal expressed in microseconds

volatile int wave1 = 0;

int i = 0;
int sample;

void setup() {
analogWriteResolution(12);  // set the analog output resolution to 12 bit (4096 levels)

}

void loop() {
// Read the the potentiometer and map the value  between the maximum and the minimum sample available
// 1 Hz is the minimum freq for the complete wave
// 170 Hz is the maximum freq for the complete wave. Measured considering the loop and the analogRead() time
sample = map(55, 0, 4095, 0, oneHzSample);
sample = constrain(sample, 0, oneHzSample);

analogWrite(DAC1, waveformsTable[wave1][i]);  // write the selected waveform on DAC1

i++;
if(i == maxSamplesNum)  // Reset the counter to repeat the wave
i = 0;

delayMicroseconds(sample);  // Hold the sample value for the sample time
}

// function hooked to the interrupt on digital pin 3
void wave1Select() {
wave1++;
if(wave1 == 4)
wave1 = 0;
}
``````
``````#ifndef _Waveforms_h_
#define _Waveforms_h_

#define maxWaveform 4
#define maxSamplesNum 120

static int waveformsTable[maxWaveform][maxSamplesNum] = {
// Sin wave
{
0x7ff, 0x86a, 0x8d5, 0x93f, 0x9a9, 0xa11, 0xa78, 0xadd, 0xb40, 0xba1,
0xbff, 0xc5a, 0xcb2, 0xd08, 0xd59, 0xda7, 0xdf1, 0xe36, 0xe77, 0xeb4,
0xeec, 0xf1f, 0xf4d, 0xf77, 0xf9a, 0xfb9, 0xfd2, 0xfe5, 0xff3, 0xffc,
0xfff, 0xffc, 0xff3, 0xfe5, 0xfd2, 0xfb9, 0xf9a, 0xf77, 0xf4d, 0xf1f,
0xeec, 0xeb4, 0xe77, 0xe36, 0xdf1, 0xda7, 0xd59, 0xd08, 0xcb2, 0xc5a,
0xbff, 0xba1, 0xb40, 0xadd, 0xa78, 0xa11, 0x9a9, 0x93f, 0x8d5, 0x86a,
0x7ff, 0x794, 0x729, 0x6bf, 0x655, 0x5ed, 0x586, 0x521, 0x4be, 0x45d,
0x3ff, 0x3a4, 0x34c, 0x2f6, 0x2a5, 0x257, 0x20d, 0x1c8, 0x187, 0x14a,
0x112, 0xdf, 0xb1, 0x87, 0x64, 0x45, 0x2c, 0x19, 0xb, 0x2,
0x0, 0x2, 0xb, 0x19, 0x2c, 0x45, 0x64, 0x87, 0xb1, 0xdf,
0x112, 0x14a, 0x187, 0x1c8, 0x20d, 0x257, 0x2a5, 0x2f6, 0x34c, 0x3a4,
0x3ff, 0x45d, 0x4be, 0x521, 0x586, 0x5ed, 0x655, 0x6bf, 0x729, 0x794
}
,

};

#endif m
``````

I made a circuit like this.

Now, I have a trouble that I have no idea how to generate time-shifting sound.
I have known
map(55, 0, 4095, 0, oneHzSample)
generates 70 Hz sound and
map(65, 0, 4095, 0, oneHzSample)
generates 60 Hz sound.

I want to generate time-shifting sound between these area.

the code might need a for loop structure, but I don't know how to build a correct code.