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;
}
}
}