keyboard.press all keys from one input ?

hello I have a project showing at a gallery tommorow ! and so far everything has gone well. the project consists of a makey makey circuit as show in this video http://www.youtube.com/watch?v=WDPTA0-fbNE

essentially 5v goes to the positive rail which connects to an A pin via a 1 mega ohms resistor then An unconnected wire is left to make contact with another unconnected wire which is in the negative rail on the other side. the final outcome involves playing notes on the logic keyboard. everything was seemingly fine until today when I noticed that all the inputs except one would play all 5 other notes/ would keybaord.press all keys except one.

at first I thought that it was a wiring problem and that some voltage was bleeding over from adjacent pins but currently I have to inputs stemming from two different rails on pin A 0 and pin A5 and am still having the same problem.

I came to the conclusion that it might be a coding problem although I am sure that It was functioning fine last night although pherhaps I was not paying attention. Any help would be much appreciated as I REALLY NEED TO FIX THIS FOR THE OPENING

:fearful:

#include <MovingAvarageFilter.h>

MovingAvarageFilter movingAvarageFilter1(20);
MovingAvarageFilter movingAvarageFilter2(20);
MovingAvarageFilter movingAvarageFilter3(20);
MovingAvarageFilter movingAvarageFilter4(20);
MovingAvarageFilter movingAvarageFilter5(20);
MovingAvarageFilter movingAvarageFilter6(20);
boolean check1 = false;
boolean check2 = false;
boolean check3 = false;
boolean check4 = false;
boolean check5 = false;
boolean check6 = false;
void setup() {

  Serial.begin(115200);     
}

void loop() {        

  float output1 = movingAvarageFilter1.process(analogRead(0));       
  float output2 = movingAvarageFilter2.process(analogRead(1));
  float output3 = movingAvarageFilter3.process(analogRead(2));
  float output4 = movingAvarageFilter4.process(analogRead(3));
  float output5 = movingAvarageFilter5.process(analogRead(4));
  float output6 = movingAvarageFilter6.process(analogRead(5));
  if (output1 < 200 ) {   // you can change this parameter to fine tune the sensitivity
    
    if (!check1){         
      Keyboard.press(KEY_CAPS_LOCK);
 Keyboard.press ('d');     
      Serial.println(output1);           
      check1 = !check1;   
    }         
  }

  if (output1 >600) {     
    if (check1){ 
Keyboard.release ('d');     
      check1 = !check1;   
    }     
  }

  if (output2 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check2){         
      Keyboard.press('s');         
      Serial.println(output2);           
      check2 = !check2;   
    }         
  }

  if (output2 >600) {     
    if (check2){
Keyboard.release ('s');      
      check2 = !check2;   
    }     
  }
 if (output3 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check3){         
      Keyboard.press('f');         
      Serial.println(output3);           
      check3 = !check3;   
    }         
  }

  if (output3 >600) {     
    if (check3){
Keyboard.release ('f');      
      check3 = !check3;   
    }     
  }
  
  if (output4 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check4){         
      Keyboard.press('g');         
      Serial.println(output4);           
      check4 = !check4;   
    }         
  }

  if (output4 >600) {     
    if (check4){
Keyboard.release ('g');      
      check4 = !check4;   
    }     
  }
if (output5 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check5){         
      Keyboard.press('h');         
      Serial.println(output5);           
      check5 = !check5;   
    }         
  }

  if (output5 >600) {     
    if (check5){
Keyboard.release ('h');      
      check5 = !check5;   
    }     
  }
  
if (output6 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check6){         
      Keyboard.press('j');         
      Serial.println(output6);           
      check6 = !check6;   
    }         
  }

  if (output6 >600) {     
    if (check6){
Keyboard.release ('j');      
      check6 = !check6;   
    }     
    
  }
}
MovingAvarageFilter movingAvarageFilter1(20);
MovingAvarageFilter movingAvarageFilter2(20);
MovingAvarageFilter movingAvarageFilter3(20);
MovingAvarageFilter movingAvarageFilter4(20);
MovingAvarageFilter movingAvarageFilter5(20);
MovingAvarageFilter movingAvarageFilter6(20);

You’ve never heard of arrays?
You’ve never heard of arrays?
You’ve never heard of arrays?
You’ve never heard of arrays?
You’ve never heard of arrays?
You’ve never heard of arrays?

  float output1 = movingAvarageFilter1.process(analogRead(0));       
  float output2 = movingAvarageFilter2.process(analogRead(1));
  float output3 = movingAvarageFilter3.process(analogRead(2));
  float output4 = movingAvarageFilter4.process(analogRead(3));
  float output5 = movingAvarageFilter5.process(analogRead(4));
  float output6 = movingAvarageFilter6.process(analogRead(5));

You get some output. What is it?

Your code
runs all over
the page,
making it very
hard to read.
Why is that?

Use Tools + Auto Format!

I REALLY NEED TO FIX THIS FOR THE OPENING

So? Fix it. There is no reason to be screaming at us. We didn’t cause your problems.

sorry it wasn’t meant to be a scream at the forum more a just a generalised emphasis of panic.

I pulled all the code to the left edge then auto formatted it. I have heard of but never used arrays.? do you think that could solve my problem. the output is a voltage reading at one of the analogue pins.

#include <MovingAvarageFilter.h>

MovingAvarageFilter movingAvarageFilter1(20);
MovingAvarageFilter movingAvarageFilter2(20);
MovingAvarageFilter movingAvarageFilter3(20);
MovingAvarageFilter movingAvarageFilter4(20);
MovingAvarageFilter movingAvarageFilter5(20);
MovingAvarageFilter movingAvarageFilter6(20);
boolean check1 = false;
boolean check2 = false;
boolean check3 = false;
boolean check4 = false;
boolean check5 = false;
boolean check6 = false;
void setup() {

  Serial.begin(115200);     
}

void loop() {        

  float output1 = movingAvarageFilter1.process(analogRead(0));       
  float output2 = movingAvarageFilter2.process(analogRead(1));
  float output3 = movingAvarageFilter3.process(analogRead(2));
  float output4 = movingAvarageFilter4.process(analogRead(3));
  float output5 = movingAvarageFilter5.process(analogRead(4));
  float output6 = movingAvarageFilter6.process(analogRead(5));

  if (output1 < 200 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check1){         
      Keyboard.press(KEY_CAPS_LOCK);
      Keyboard.press ('d');     
      Serial.println(output1);           
      check1 = !check1;   
    }         
  }
  if (output1 >600) {     
    if (check1){ 
      Keyboard.release ('d');     
      check1 = !check1;   
    }     
  }

  if (output2 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check2){         
      Keyboard.press('s');         
      Serial.println(output2);           
      check2 = !check2;   
    }         
  }
  if (output2 >600) {     
    if (check2){
      Keyboard.release ('s');      
      check2 = !check2;   
    }     
  }
  if (output3 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check3){         
      Keyboard.press('f');         
      Serial.println(output3);           
      check3 = !check3;   
    }         
  }
  if (output3 >600) {     
    if (check3){
      Keyboard.release ('f');      
      check3 = !check3;   
    }     
  }

  if (output4 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check4){         
      Keyboard.press('g');         
      Serial.println(output4);           
      check4 = !check4;   
    }         
  }
  if (output4 >600) {     
    if (check4){
      Keyboard.release ('g');      
      check4 = !check4;   
    }     
  }
  if (output5 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check5){         
      Keyboard.press('h');         
      Serial.println(output5);           
      check5 = !check5;   
    }         
  }
  if (output5 >600) {     
    if (check5){
      Keyboard.release ('h');      
      check5 = !check5;   
    }     
  }
  if (output6 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check6){         
      Keyboard.press('j');         
      Serial.println(output6);           
      check6 = !check6;   
    }         
  }
  if (output6 >600) {     
    if (check6){
      Keyboard.release ('j');      
      check6 = !check6;   
    }     

  }
}

This comes up fairly often. Here's a response from a prior thread:

There is only one ADC, shared between the analog pins. The result is that one reading can be impacted by the last. A common workaround is to read twice, ignoring the first reading. When I posted something like this (not so recently now), Grumpy Mike added this:

Quote That is only true if the input impedance to the ADC is significantly higher than 10K. Keep it at 10K and you can sample at the maximum rate.

ahh thank you very much ! can you provide a link to that previous thread As I am not exactly sure how to go about programming the read twice ignore first method.? thank you immensely you may have saved my bacon from aggressive frying.

cheers

sam

Something like:

int Reading;

Reading = analogRead(0);
Reading = analogRead(0);
float output1 = movingAvarageFilter1.process(Reading);

the output is a voltage reading at one of the analogue pins.

No. The reading is a ratio of the actual voltage to the reference voltage. But, that's less important than knowing what the ACTUAL values are. Print them, so you KNOW!.

When you KNOW what is causing the problem, or what is not, it will be much easier to fix the code.

If the values in outputN are reasonable, then the problem is elsewhere. If the values in outputN are not reasonable, then fixing the code that uses the values will accomplish nothing.

I re-wrote my code and the problem just fixed itself , this was last night however when I rebooted my computer this morning the problem returned , I tried this
but I’m not even sure I have changed anything , the problem is still persisting. If anyone could help that would be really great.

thank you very much

#include <MovingAvarageFilter.h>

MovingAvarageFilter movingAvarageFilter1(20);
MovingAvarageFilter movingAvarageFilter2(20);
MovingAvarageFilter movingAvarageFilter3(20);
MovingAvarageFilter movingAvarageFilter4(20);
MovingAvarageFilter movingAvarageFilter5(20);
MovingAvarageFilter movingAvarageFilter6(20);
boolean check1 = false;
boolean check2 = false;
boolean check3 = false;
boolean check4 = false;
boolean check5 = false;
boolean check6 = false;




void setup() {

  Serial.begin(115200);     
}

void loop() {        

  float output1 = movingAvarageFilter1.process(analogRead(0));
  int Reading;

  output1 = analogRead(0);
  output1 = analogRead(0);  
  float output2 = movingAvarageFilter2.process(analogRead(1));
  int Reading1;

  output2 = analogRead(1);
  output2 = analogRead(1);  
  float output3 = movingAvarageFilter3.process(analogRead(2));
  int Reading2;

  output3 = analogRead(2);
  output3 = analogRead(2);
  float output4 = movingAvarageFilter4.process(analogRead(3));
  int Reading3;

  output4 = analogRead(3);
  output4 = analogRead(3);
  float output5 = movingAvarageFilter5.process(analogRead(4));
  int Reading4;

  output5 = analogRead(4);
  output5 = analogRead(4);
  float output6 = movingAvarageFilter6.process(analogRead(5));
  int Reading5;

  output6 = analogRead(5);
  output6 = analogRead(5);
  if (output1 < 200 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check1){         
      Keyboard.press(KEY_CAPS_LOCK);
      Keyboard.press ('d');     
      Serial.println(output1);           
      check1 = !check1;   
    }         
  }

  if (output1 >600) {     
    if (check1){ 
      Keyboard.release ('d');
      check1 = !check1;   
    }     
  }

  if (output2 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check2){         
      Keyboard.press('f');         
      Serial.println(output2);           
      check2 = !check2;   
    }         
  }

  if (output2 >600) {     
    if (check2){
      Keyboard.release ('f');      
      check2 = !check2;   
    }     
  }

  if (output3 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check3){         

      Keyboard.press ('g');     
      Serial.println(output3);           
      check3 = !check3;   
    }         
  }

  if (output3 >600) {     
    if (check3){ 
      Keyboard.release ('g');     
      check3 = !check3;   

    }
  }
  if (output4 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check4){         

      Keyboard.press ('h');     
      Serial.println(output4);           
      check4 = !check4;   
    }         
  }

  if (output4 >600) {     
    if (check4){ 
      Keyboard.release ('h');     
      check4 = !check4; 

    }
  }
  if (output5 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check5){         

      Keyboard.press ('j');     
      Serial.println(output5);           
      check5 = !check5;   
    }         
  }

  if (output5 >600) {     
    if (check5){ 
      Keyboard.release ('j');     
      check5 = !check5; 
    }
  }
  if (output6 < 590 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check6){         

      Keyboard.press ('k');     
      Serial.println(output6);           
      check6 = !check6;   
    }         
  }

  if (output6 >600) {     
    if (check6){ 
      Keyboard.release ('k');     
      check6 = !check6; 
    }
  }
}
  float output1 = movingAvarageFilter1.process(analogRead(0));
  int Reading;

  output1 = analogRead(0);
  output1 = analogRead(0);

Read and store a reading. Then, on the off chance that the first reading was bad, take to more readings and discard them.

Not at all useful.

sorry I really do intend to sit down and learn C properly over them summer but at the moment I am swamped with work but i can seee how it could be annoying to have people making simple mistakes because they lack an understanding of the fundamental mechanics of something.

I tried this

  int Reading;

  output1 = analogRead(0);
  output1 = analogRead(0);
  float output1 = movingAvarageFilter1.process(analogRead(0));

I was of course wrong and was told that Output 1 had not been declared within the scope. would you enlighten me?

cheers

samhallett:
would you enlighten me?

You have to define variables before you can use them. Here you define output1 on the last line, but you are trying to use it in the preceding lines. The line containing this is where the variable is defined:

If you are not going to send the first two values to the filter class, just discard the results:

  analogRead(0);
  analogRead(0);  

  float output1 = movingAvarageFilter1.process(analogRead(0));

thanks very much , Am I right in thinking this would be correct , aside from all the unnecessary moving average filter inclusions ?

#include <MovingAvarageFilter.h>

MovingAvarageFilter movingAvarageFilter1(20);
MovingAvarageFilter movingAvarageFilter2(20);
MovingAvarageFilter movingAvarageFilter3(20);
MovingAvarageFilter movingAvarageFilter4(20);
MovingAvarageFilter movingAvarageFilter5(20);
MovingAvarageFilter movingAvarageFilter6(20);
boolean check1 = false;
boolean check2 = false;
boolean check3 = false;
boolean check4 = false;
boolean check5 = false;
boolean check6 = false;
void setup() {

  Serial.begin(115200);     
}

void loop() {        

  analogRead(0);
  analogRead(0);  
  float output1 = movingAvarageFilter1.process(analogRead(0));       
  analogRead(1);
  analogRead(1);
  float output2 = movingAvarageFilter2.process(analogRead(1));
  analogRead(2);
  analogRead(2);
  float output3 = movingAvarageFilter3.process(analogRead(2));
  analogRead(3);
  analogRead(3);
  float output4 = movingAvarageFilter4.process(analogRead(3));
  analogRead(4);
  analogRead(4);
  float output5 = movingAvarageFilter5.process(analogRead(4));
  analogRead(5);
  analogRead(5);
  float output6 = movingAvarageFilter6.process(analogRead(5));

  if (output1 < 690 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check1){         
      Keyboard.press(KEY_CAPS_LOCK);
      Keyboard.press ('d');     
      Serial.println(output1);           
      check1 = !check1;   
    }         
  }
  if (output1 >700) {     
    if (check1){ 
      Keyboard.release ('d');     
      check1 = !check1;   
    }     
  }

  if (output2 < 690 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check2){         
      Keyboard.press('s');         
      Serial.println(output2);           
      check2 = !check2;   
    }         
  }
  if (output2 >700) {     
    if (check2){
      Keyboard.release ('s');      
      check2 = !check2;   
    }     
  }
  if (output3 < 690 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check3){         
      Keyboard.press('f');         
      Serial.println(output3);           
      check3 = !check3;   
    }         
  }
  if (output3 >700) {     
    if (check3){
      Keyboard.release ('f');      
      check3 = !check3;   
    }     
  }

  if (output4 < 790 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check4){         
      Keyboard.press('g');         
      Serial.println(output4);           
      check4 = !check4;   
    }         
  }
  if (output4 >800) {     
    if (check4){
      Keyboard.release ('g');      
      check4 = !check4;   
    }     
  }
  if (output5 < 690 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check5){         
      Keyboard.press('h');         
      Serial.println(output5);           
      check5 = !check5;   
    }         
  }
  if (output5 >700) {     
    if (check5){
      Keyboard.release ('h');      
      check5 = !check5;   
    }     
  }
  if (output6 < 690 ) {   // you can change this parameter to fine tune the sensitivity
    if (!check6){         
      Keyboard.press('j');         
      Serial.println(output6);           
      check6 = !check6;   
    }         
  }
  if (output6 >700) {     
    if (check6){
      Keyboard.release ('j');      
      check6 = !check6;   
    }     

  }
}

Am I right in thinking this would be correct , aside from all the unnecessary moving average filter inclusions ?

Yes, that looks better. Generally, though, you only need to discard one value from the analog port to get more accurate results.

essentially 5v goes to the positive rail which connects to an A pin via a 1 mega ohms resistor then An unconnected wire is left to make contact with another unconnected wire which is in the negative rail on the other side. the final outcome involves playing notes on the logic keyboard. everything was seemingly fine until today when I noticed that all the inputs except one would play all 5 other notes/ would keybaord.press all keys except one.

I don't understand this, and I don't want to watch a 10 minute video. Can you post a schematic? What is connected to what? What do you mean by "An unconnected wire"? A bit of wire lying around?

Still seem to be having the same problem of all of the letters being keyboard.press'ed from every input , are their any other usual workarounds to this problem ? I have tried telling it to ignore the first 4 readings now and it has not greatly helped. I've never drawn a schematic before , I'm just looking at circuit labs and Ill try and get one drawn up using that.

thanks

sam

Firefox can't find the server at file.

You can attach pictures to your post you know. A file at "localhost" is just one on your computer.

How to use this forum

sorry

Here is my shcematic , I dont think it’s what you would call a technically correct circuit digram more a visual and literal picture of what my circuit looks like. obviously I have 6 inputs so the pattern of resistor / wire to analouge port / loose ended wire / losse ended wire connected to negative rail continues up the board

I can't make any sense of that. You have 5V connected to Gnd.

Presumably you don't actually have that in your circuit.

no sorry that line is just supposed to represent the side of the board on which those pins are situated. I'm sorry I have never drawn a schematic before