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? ![]()
#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);}
}