Go Down

Topic: Quick suggestion on approaching this problem (Read 2 times) previous topic - next topic

PaulS

Code: [Select]
  chqC= analogRead(CellC);
   if  (chqC<thres){
   Serial.print("a");
   thres=chqC;
       }
      else if (chqC>thres) {
          }

Now, you have a threshold. What you don't have is any record of the previous reading's position relative to the threshold. Re-read what I said. You want to output a value if the previous reading was not above the threshold and the current one is. You MUST keep track of the previous reading.

FullyJosh

#6
Dec 31, 2012, 05:08 am Last Edit: Dec 31, 2012, 06:25 am by FullyJosh Reason: 1

Code: [Select]
 chqC= analogRead(CellC);
  if  (chqC<thres){
  Serial.print("a");
  thres=chqC;
      }
     else if (chqC>thres) {
         }

Now, you have a threshold. What you don't have is any record of the previous reading's position relative to the threshold. Re-read what I said. You want to output a value if the previous reading was not above the threshold and the current one is. You MUST keep track of the previous reading.


Okay so I have been trying to rationalize what you have been saying and I gave it a shot. I am totally missing the boat on something. I tried to explain what I was thinking.

Code: [Select]
chqC= analogRead(CellC);
 
 if (chqC<thres){
   store=HIGH;    //store previous value as high if it is less than the threshold
    }
    else if (chqC>=thres) {
      store=LOW; //store previous value as low if it is greater than the threshold
        }

 if ((store=HIGH) && (chqC>=thres)){ //if the stored value is high and the current value is grater than the threshold then print "a"
   Serial.print("a");
 }
}{/code]


Is this not working because the store value is getting overwritten before

I was reading this article http://siliconrepublic.blogspot.ca/2010/08/this-summer-i-have-been-tinkering-with.htmlg-with.html and he was saying something along the lines of aac keys repetitively hitting the key and doesn't allow the user to physically hold down the key for periods of time. In my case that would be holding down a note.

Is it possible I need to try approaching this problem differently?

PaulS

Code: [Select]
  if ((store=HIGH) && (chqC>=thres)){ //if the stored value is high and the current value is grater than the threshold then print "a"

Assigning a value to HIGH in the if test is probably not what you want to be doing.

FullyJosh

#8
Dec 31, 2012, 02:03 pm Last Edit: Dec 31, 2012, 02:15 pm by FullyJosh Reason: 1

Code: [Select]
 if ((store=HIGH) && (chqC>=thres)){ //if the stored value is high and the current value is grater than the threshold then print "a"

Assigning a value to HIGH in the if test is probably not what you want to be doing.


I tried assigning other values.  Neither seemed to do the trick.  The high and low thing was just something I tried before posting when I was testing a bunch of possible solutions.  

Anything else you suggest I try?

DerekErb

I'm new to Arduino but old to C programming... could this possibly just be the simple assignment rather than test?

As you're already setting store to HIGH or LOW before the test...

Rather than
Code: [Select]

if ((store=HIGH) && (chqC>=thres)){


Shouldn't it be?
Code: [Select]

if ((store==HIGH) && (chqC>=thres)) {


Go Up