IF statements execute regardless of conditions?

I have confirmed via serial monitor that the unpressed value of the FSR is sending zero, and that the FSR behaves normally responding to pressure, yet all three IF statements execute even when the conditions aren't fulfilled. I tried this with DO WHILE and received the same results. So at least my mistakes are consistent!

I'm sure it's something simple, but where have I made an error? :blush:

#include <MIDI.h>

//FSR-based midi controller sending to hairless serial2midi
MIDI_CREATE_DEFAULT_INSTANCE();


int fsrC = 0;                  //FSR is on pin 0
int fsrVal = 0;                //variable for reading FSR value
int mappedFsrVal = 0;          //variable for holding remapped FSR value
int holding = 0;


void setup()
{
MIDI.begin(1); 
Serial.begin(115200);     // Launch MIDI and listen to channel 4
}

void loop()
{
fsrVal = analogRead(fsrC);        
mappedFsrVal = map(fsrVal, 0, 1000, 0, 127); 
//Serial.println(mappedFsrVal);//FSR reading for debug 
//Serial.println(fsrVal);    //FSR reading for debug  
   
if((fsrVal > 1) && (holding = 0)){
   
   
        MIDI.sendNoteOn(60,mappedFsrVal,1);               //ON
        delay(1000);	//delay for debugging, else hairless crash 	       
        holding =1 ;
}
    
     
    if((fsrVal > 1) && (holding =1));
    
{
                     
      MIDI.sendControlChange(2,mappedFsrVal,1);      //CC
      delay(1000);
    
}   
    if((mappedFsrVal = 0) && (holding = 1));{
            MIDI.sendNoteOff(60,0,1);
            holding = 0;
            delay(1000);}
}

This is wrong:

(holding = 0)

You must do it like:

(holding == 0)

In the IF conditions? I tried that, and it's still sending messages at zero, and not switching to the condition change statement. All statements still execute. That does clear one issue up I guess, but it still is behavior inappropriately. Thank you, though.

(holding = 0)
(holding =1)

All wrong. It's not illegal to use in C/C++ but wrong. Use conditional equals (==).

OK. I see the error, is the " ; " at the end of each if line!!! Remove it and it will work.

Try:

#include <MIDI.h>

//FSR-based midi controller sending to hairless serial2midi
MIDI_CREATE_DEFAULT_INSTANCE();


int fsrC = 0;                  //FSR is on pin 0
int fsrVal = 0;                //variable for reading FSR value
int mappedFsrVal = 0;          //variable for holding remapped FSR value
int holding = 0;


void setup()
{
  MIDI.begin(1);
  Serial.begin(115200);     // Launch MIDI and listen to channel 4
}

void loop()
{
  fsrVal = analogRead(fsrC);
  mappedFsrVal = map(fsrVal, 0, 1000, 0, 127);
  //Serial.println(mappedFsrVal);//FSR reading for debug
  //Serial.println(fsrVal);    //FSR reading for debug

  if ((fsrVal > 1) && (holding == 0)) {


    MIDI.sendNoteOn(60, mappedFsrVal, 1);             //ON
    delay(1000);	//delay for debugging, else hairless crash
    holding = 1 ;
  }


  if ((fsrVal > 1) && (holding == 1)) {

    MIDI.sendControlChange(2, mappedFsrVal, 1);    //CC
    delay(1000);

  }
  if ((mappedFsrVal = 0) && (holding == 1)) {
    MIDI.sendNoteOff(60, 0, 1);
    holding = 0;
    delay(1000);
  }
}

and see the differences.

hehehe I knew that, I was ummm, err, just testing the community? :sweat_smile:

.
.
.
Thanks! :grin:

It almost seams that! :slight_smile: 2 errors in the same line, I see the first in the first attempt and the second in the second, not too bad. :smiley: