Frequency measurement problem

Hi there,

For our 2nd semester in the university we were given a DEAP polymer string(stretch sensor) and asked to implement it in

our semester project. We decided to make something like a trivia boardgame and use the sensor as a controller. The stretch sensor is called PolyPower, which is a capacitive sensor where the capacitance increases when stretched. (datasheet attached)

We used a 555 timer Astable oscillator circuit to generate a square wave and send the signal to the Arduino. We used the pulseIn() function to read the frequency from the arduino pins(2,3) and the problem arised. We have trouble saving a single value to a variable ( problem is commented in the attached code) - the function was taken from here NameBright - Coming Soon

/* Variables for the pulsein freqMeasurement*/

// period of pulse accumulation and serial output, milliseconds
#define MainPeriod 100
long previousMillis = 0; // will store last time of the cycle end
volatile unsigned long duration=0; // accumulates pulse width
volatile unsigned int pulsecount=0;
volatile unsigned long previousMicros=0;
long previousMillis2 = 0; // will store last time of the cycle end
volatile unsigned long duration2=0; // accumulates pulse width
volatile unsigned int pulsecount2=0;
volatile unsigned long previousMicros2=0;
float Freq1 = 0;
float Freq2 = 0;


/* Game variables */

const int  button = 7;
int flag = 1;
boolean time_runs_out = false;


/* player variables*/
int pewpew = 0;
int player1adjust = 0;
int player2adjust = 0;

int player1locked = 0;
int player2locked = 0;

int player1LED = 13;

int player1_initF = 0; 
int player2_initF = 0;



void setup()
{
  Serial.begin(19200); 
  attachInterrupt(0, myinthandler, RISING);
  attachInterrupt(1, myinthandler2, RISING);
  pinMode(button, INPUT);
  pinMode(player1LED, OUTPUT);

  
}

void loop()
{
   freqMeasure();
   if(flag == 1){
    player1_initF = Freq1; // Problem assigning this value ? For some reason is allways 0 ? even though Freq1 has a value
    flag = 0;
   }
 
  if (player1_initF >= 505) {
  Serial.println("TOO BIG");
}else{
int buttonstate = digitalRead(button);
      if(1 == 1){
       player1locked = (player1_initF - Freq1);
       Serial.print(player1_initF);
       Serial.print("\t");
       Serial.print((int)Freq1);
       Serial.print("\t");
       Serial.println(map(Freq1, 325, 390, 100, 0));

}else{
}
}
}


void freqMeasure(){

unsigned long currentMillis = millis();
  unsigned long currentMillis2 = millis();
  if (currentMillis - previousMillis >= MainPeriod) 
  {
    previousMillis = currentMillis;   
    // need to bufferize to avoid glitches
    unsigned long _duration = duration;
    unsigned long _pulsecount = pulsecount;
    duration = 0; // clear counters
    pulsecount = 0;
    Freq1 = 1e6 / float(_duration);
    Freq1 *= _pulsecount; // calculate F
    // output time and frequency data to RS232
    
  }
  if (currentMillis2 - previousMillis2 >= MainPeriod) 
  {
    previousMillis2 = currentMillis2;   
    // need to bufferize to avoid glitches
    unsigned long _duration2 = duration2;
    unsigned long _pulsecount2 = pulsecount2;
    duration2 = 0; // clear counters
    pulsecount2 = 0;
    Freq2 = 1e6 / float(_duration2);
    Freq2 *= _pulsecount2; // calculate F
    // output time and frequency data to RS232


  }



}
void myinthandler() // interrupt handler
{
  unsigned long currentMicros = micros();
  duration += currentMicros - previousMicros;
  previousMicros = currentMicros;
  pulsecount++;
}
void myinthandler2() // interrupt handler
{
  unsigned long currentMicros2 = micros();
  duration2 += currentMicros2 - previousMicros2;
  previousMicros2 = currentMicros2;
  pulsecount2++;
}

For any questions about anything, ask...
Thanks in advance !

094F01260129_Stretch_Sensor_Data_Sheet.pdf (328 KB)