Fixed buffer overflow which was setting the phase to random values
every cycle, leading to weirdnessmain
parent
29d7156d16
commit
64a04067e0
|
@ -14,7 +14,6 @@ Adafruit_MCP4728 mcp;
|
|||
unsigned int phase;
|
||||
unsigned int repeats;
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
@ -25,17 +24,16 @@ void setup() {
|
|||
}
|
||||
}
|
||||
|
||||
// mcp.setSpeed(400000L);
|
||||
// mcp.setSpeed(800000L);
|
||||
randomSeed(analogRead(A0));
|
||||
mcp.setSpeed(800000L);
|
||||
|
||||
phase=0;
|
||||
pluck();
|
||||
}
|
||||
|
||||
byte waveform[nsamp];
|
||||
|
||||
|
||||
void pluck(){
|
||||
Serial.println("pluck");
|
||||
for (int i=0; i<nsamp; ++i){
|
||||
waveform[i]=random(256);
|
||||
}
|
||||
|
@ -46,7 +44,7 @@ void loop() {
|
|||
int p0 = phase;
|
||||
s1 = waveform[phase];
|
||||
phase += 1;
|
||||
if( phase > nsamp ) {
|
||||
if( phase >= nsamp ) {
|
||||
phase = 0;
|
||||
repeats += 1;
|
||||
}
|
||||
|
@ -56,7 +54,6 @@ void loop() {
|
|||
if( repeats > 100 ) {
|
||||
pluck();
|
||||
repeats = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue