Hi all,
I was trying out the following code on my arduino and getting an error with the following code. The idea is that is plays the rythm you input via an array in a loop. When you push the program button it goes into record mode and exits the loop to record a series of delays which creates a rythm for the loop phase of the program.
So my two questions are I get one main error with it. And also when I solve this error I imagine I will need a way to code it so the program goes back to the loop after recording. But I though first things first why does it error on me.
Any ideas?
#include <Servo.h>
Servo servo1; // create first servo object to control first servo
int FSR = 0; // FSR on pin 0. CHange this to an FSR
int programSwitch = 2; // If this is high we program a new code.
int tapReadings[20]; // When someone knocks this array fills with delays between knocks.
int programButtonPressed = false; // Flag so we remember the programming button setting at the end of the cycle.
int i = 0;
int totaltaps=0;
int currentTapNumber=0;
void setup()
{
pinMode(programSwitch, INPUT);
servo1.attach(6); // attaches the first servo on pin 6 to the first servo object
}
void loop()
{
if (programSwitch==false)// will repeat what was enterred while unit is not in enterring mode.
//Section where pattern is replayed
{
for (i = 0; i!= currentTapNumber; i = i + 1)
{servo1.write(170);
servo1.write(0);
delay(tapReadings*); // pauses between rythm*
if (i = currentTapNumber)
{i=0;}
}
if (programSwitch==true)
{
taprecording();
{
void taprecording(){
Serial.println(“Start tapping”);
// First lets reset the listening array.
int i = 0;
for (i=0;i<20;i=i+1)
{
tapReadings=0;
tapReadings = analogRead(FSR);
}
{
int currenttapNumber=0; // Incrementer for the array.
int startTime=millis(); // Reference for when this knock started.
int now=millis();
}
do
{
now=millis();
tapReadings[currentTapNumber] = now-startTime;
currentTapNumber ++; //increment the counter
startTime=now;
now=millis();
}
while (programSwitch==true); //I don’t know if this is needed due to what is up top.
}