Help with simple code for Makey Makey-like behavior

Hi everyone.
I followed the instructions from How to make something like "Makey Makey" using Arduino | Arduino Blog to get my brand new Leonardo working like a Makey Makey. It went fine, no trouble at all, but I wanted to expand the code and circuit to check for two different possible circuit completions instead of one. I basically doubled the circuit, connecting my addition to the A1 pin. In the code, I just doubled everything and renamed the variables. Nothing complicated--but it doesn't work for some reason! Can anyone help? Here is the code:

// Makey Makey using Arduino Leonardo

#include <MovingAvarageFilter.h>

MovingAvarageFilter movingAvarageFilter(20);
 
 
boolean check0 = false;
boolean check1 = false;
 
 
 
void setup() {
 
Serial.begin(115200);     
 
}
 
 
void loop() {        
 
// declare input and output variables
 
float input0 =  analogRead(0); 
float output0 = 0;
 
float input1 =  analogRead(1);
float output1 = 0;
 
output0 = movingAvarageFilter.process(input0);
output1 = movingAvarageFilter.process(input1); 
 
// Check for connection to analog 0
 
if (output0 < 200 ) {   // you can change this parameter to fine tune the sensitivity
if (!check0){         
Keyboard.print("r");         
Serial.println(output0);           
check0 = !check0;   
  }         
  }
 
 
if (output0 > 600) {     
  if (check0){               
  check0 = !check0;   
  }     
  }
 
// Check for connection to analog 1
 
if (output1 < 200 ) {   // you can change this parameter to fine tune the sensitivity
if (!check1){         
Keyboard.print("y");         
Serial.println(output1);           
check1 = !check1;   
  }         
  }
 
 
if (output1 > 600) {     
  if (check1){               
  check1 = !check1;   
  }     
  }

// Done Checking

}

For reference, the original code for the project (which works fine) looks like this:

#include <MovingAvarageFilter.h> 
 
MovingAvarageFilter movingAvarageFilter(20);
 
 
boolean check = false;
 
 
 
 
void setup() {
 
Serial.begin(115200);     
 
}
 
 
void loop() {        
 
// declare input and output variables
 
float input =  analogRead(0); // without a real input, looking at the step respons (input at unity, 1)
 
float output = 0;
 
 
output = movingAvarageFilter.process(input);
 
// here we call the fir routine with the input. The value 'fir' spits out is stored in the output variable.
 
 
 
if (output < 200 ) {   // you can change this parameter to fine tune the sensitivity
if (!check){         
Keyboard.print("d");         
Serial.println(output);           
check = !check;   
  }         
  }
 
 
if (output >600) {     
  if (check){               
  check = !check;   
  }     
  }
 
 
}

I have no idea but maybe try:

MovingAvarageFilter movingAvarageFilter1(20);
MovingAvarageFilter movingAvarageFilter2(20);
.
.
.
output0 = movingAvarageFilter1.process(input0);
output1 = movingAvarageFilter2.process(input1);

What does MovingAvarageFilter do?
You have both sensors contribute to one moving average, there should be one output.

YES! LarryD, that was it! I have some experience with C++ (not much, and I'm totally new to Arduino).
It never even crossed my mind to double that line, even though I had doubled everything else. I guess it didn't jump out at me as being a variable.

GoForSmoke:
What does MovingAvarageFilter do?

I'm not 100% sure, but the way I understand it: closing a circuit with one's body creates a lot of variation in the output, so MovingAverageFilter takes some sample readings and averages them to filter out the 'noise' and give more predictable behavior.

Thanks guys! I'm gonna expand this baby now to include 6 keys! :smiley:

I'm gonna expand this baby now to include 6 keys

and use arrays I presume

ioannes:
YES! LarryD, that was it! I have some experience with C++ (not much, and I'm totally new to Arduino).
It never even crossed my mind to double that line, even though I had doubled everything else. I guess it didn't jump out at me as being a variable.

GoForSmoke:
What does MovingAvarageFilter do?

I'm not 100% sure, but the way I understand it: closing a circuit with one's body creates a lot of variation in the output, so MovingAverageFilter takes some sample readings and averages them to filter out the 'noise' and give more predictable behavior.

Thanks guys! I'm gonna expand this baby now to include 6 keys! :smiley:

From the look of the video it's either measuring conductivity or capacitance. My guess is the first.