LED's the wrong way

HI there,
this is my first project. Trying to build a MIDI controller. It is functional now, but the LEDS are not behaving the way I want.
I have 5 foot switches with LED rings. I want the LED's to be always on; when I press a foot switch I want that LED ring. from that button to switch off for a short time and switch on again.
With the code below: when I press one foot switch, the other LED's switch off and on again. So it's the other way around. Can anyone point me in the right direction how to fix this?
Thanks

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();


#define FS1 2
#define FS2 3
#define FS3 4
#define FS4 5
#define FS5 6

#define LEDFS1 8
#define LEDFS2 9
#define LEDFS3 10
#define LEDFS4 11
#define LEDFS5 12


void setup() {

  // Set pin modes
  pinMode(FS1, INPUT);
  pinMode(FS2, INPUT);
  pinMode(FS3, INPUT);
  pinMode(FS4, INPUT);
  pinMode(FS5, INPUT);

  pinMode(LEDFS1, OUTPUT);
  pinMode(LEDFS2, OUTPUT);
  pinMode(LEDFS3, OUTPUT);
  pinMode(LEDFS4, OUTPUT);
  pinMode(LEDFS5, OUTPUT);

  digitalWrite(FS1, HIGH);
  digitalWrite(FS2, HIGH);
  digitalWrite(FS3, HIGH);
  digitalWrite(FS4, HIGH);
  digitalWrite(FS5, HIGH);


  MIDI.begin(31250);

  // Blink LED on start
  for (int i = 0; i < 2; i++) {
    digitalWrite(LEDFS1, HIGH);
    delay(60);
    digitalWrite(LEDFS1, LOW);
    delay(60);
    digitalWrite(LEDFS2, HIGH);
    delay(60);
    digitalWrite(LEDFS2, LOW);
    delay(60);
    digitalWrite(LEDFS3, HIGH);
    delay(60);
    digitalWrite(LEDFS3, LOW);
    delay(60);
    digitalWrite(LEDFS4, HIGH);
    delay(60);
    digitalWrite(LEDFS4, LOW);
    delay(60);
    digitalWrite(LEDFS5, HIGH);
    delay(60);
    digitalWrite(LEDFS5, LOW);
    delay(60);
  }

  delay(100);
}

unsigned long db = 150; // For switch debounce
unsigned long lastRead = millis();
// byte chn = 1; // Midi Channel to send

unsigned long ledOn = millis();
bool isLEDOn = true;

void loop() {

  // Bandhelper Next Page
  if (digitalRead(FS1) == LOW && millis() - lastRead > db) {
    turnLEDOn();
    digitalWrite(8, HIGH);
    MIDI.sendControlChange(80, 127, 1);
    lastRead = millis();
  }

  // Bandhelper Previous page
  if (digitalRead(FS2) == LOW && millis() - lastRead > db) {
    turnLEDOn();
    digitalWrite(9, HIGH);
    MIDI.sendControlChange(81, 127, 1);
    lastRead = millis();
  }

  // Bandhelper Toggle Full Screen
  if (digitalRead(FS3) == LOW && millis() - lastRead > db) {
    turnLEDOn();
    digitalWrite(10, HIGH);
    MIDI.sendControlChange(82, 127, 1);
    lastRead = millis();
  }

  // HX Stomp Toggle Tuner
  if (digitalRead(FS4) == LOW && millis() - lastRead > db) {
    turnLEDOn();
    digitalWrite(11, HIGH);
    MIDI.sendControlChange(68, 127, 2);
    lastRead = millis();
  }

  // HX Stomp Undefined
  if (digitalRead(FS5) == LOW && millis() - lastRead > db) {
    turnLEDOn();
    digitalWrite(12, HIGH);
    MIDI.sendControlChange(4, 127, 2);
    lastRead = millis();
  }


  //  Turn led on for 500ms when any switch is pressed. Turn it off after 500ms.
  if (millis() - ledOn > 500 && isLEDOn == true) {
    isLEDOn = true;
    digitalWrite(LEDFS1, HIGH);
    digitalWrite(LEDFS2, HIGH);
    digitalWrite(LEDFS3, HIGH);
    digitalWrite(LEDFS4, HIGH);
    digitalWrite(LEDFS5, HIGH);
  }

}

void turnLEDOn() {
  isLEDOn = true;
  ledOn = millis();
  digitalWrite(LEDFS1, LOW);
  digitalWrite(LEDFS2, LOW);
  digitalWrite(LEDFS3, LOW);
  digitalWrite(LEDFS4, LOW);
  digitalWrite(LEDFS5, LOW);

}

Are we supposed to guess which foot switch and which LEDs you mean?

What have you tried to fix the problem?

Post the wiring diagram.
You have defined this:

#define LEDFS1 8
#define LEDFS2 9
#define LEDFS3 10
#define LEDFS4 11
#define LEDFS5 12

Why don't You use down in the code? Okey, that's not the fault.

What if You swap HIGH and LOW in the digitalWrite to the LEDs?

How are the LEDs wired?

Hi,
Welcome to the forum.
Thanks for using code tags.

Can you please post a circuit diagram of your project please?

Thanks.. Tom.. :slight_smile:

Maybe check to make sure that HIGH and LOW make the LEDs go on & off as expected. Maybe your logic or your wiring needs to be reversed... You can write a quick little test program to test that.

TomGeorge:
Hi,
Welcome to the forum.
Thanks for using code tags.

Can you please post a circuit diagram of your project please?

Thanks.. Tom.. :slight_smile:

Hi Tom,
thank you
a link to the diagram: Diagram. Hope this helps.

What I already did do was changing all the HIGH en LOW in the Code, which gave me all kinds of behaviour, except the one I wanted. And I did a bunch of other things, but it is really trial and error.

Meanwhile I have solved the issue with this code, but I wonder if there is a different / more elegant way of doing this. I am very, very new at this, but it will def not be my last project!

Thanks again!

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();


#define FS1 2
#define FS2 3
#define FS3 4
#define FS4 5
#define FS5 6

#define LEDFS1 8
#define LEDFS2 9
#define LEDFS3 10
#define LEDFS4 11
#define LEDFS5 12


void setup() {

  // Set pin modes
  pinMode(FS1, INPUT);
  pinMode(FS2, INPUT);
  pinMode(FS3, INPUT);
  pinMode(FS4, INPUT);
  pinMode(FS5, INPUT);

  pinMode(LEDFS1, OUTPUT);
  pinMode(LEDFS2, OUTPUT);
  pinMode(LEDFS3, OUTPUT);
  pinMode(LEDFS4, OUTPUT);
  pinMode(LEDFS5, OUTPUT);

  digitalWrite(FS1, HIGH);
  digitalWrite(FS2, HIGH);
  digitalWrite(FS3, HIGH);
  digitalWrite(FS4, HIGH);
  digitalWrite(FS5, HIGH);


  MIDI.begin(31250);

  // Blink LED on start
  for (int i = 0; i < 2; i++) {
    digitalWrite(LEDFS1, HIGH);
    delay(100);
    digitalWrite(LEDFS1, LOW);
    delay(100);
    digitalWrite(LEDFS2, HIGH);
    delay(100);
    digitalWrite(LEDFS2, LOW);
    delay(100);
    digitalWrite(LEDFS3, HIGH);
    delay(100);
    digitalWrite(LEDFS3, LOW);
    delay(100);
    digitalWrite(LEDFS4, HIGH);
    delay(100);
    digitalWrite(LEDFS4, LOW);
    delay(100);
    digitalWrite(LEDFS5, HIGH);
    delay(100);
    digitalWrite(LEDFS5, LOW);
    delay(100);
  }

  delay(100);
 }

unsigned long db = 150; // For switch debounce
unsigned long lastRead = millis();
// byte chn = 1; // Midi Channel to send

unsigned long ledOn = millis();
bool isLEDOn = true;

void loop() {

  // Bandhelper Next Page
  if (digitalRead(FS1) == LOW && millis() - lastRead > db) {
    turnLEDOn();
    digitalWrite(8, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(12, HIGH);
    MIDI.sendControlChange(80, 127, 1);
    lastRead = millis();
  }

  // Bandhelper Previous page
  if (digitalRead(FS2) == LOW && millis() - lastRead > db) {
    turnLEDOn();
    digitalWrite(8, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(10, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(12, HIGH);
    MIDI.sendControlChange(81, 127, 1);
    lastRead = millis();
  }

  // Bandhelper Toggle Full Screen
  if (digitalRead(FS3) == LOW && millis() - lastRead > db) {
    turnLEDOn();
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(10, LOW);
    digitalWrite(11, HIGH);
    digitalWrite(12, HIGH);
    MIDI.sendControlChange(82, 127, 1);
    lastRead = millis();
  }

  // HX Stomp Toggle Tuner
  if (digitalRead(FS4) == LOW && millis() - lastRead > db) {
    turnLEDOn();
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(11, LOW);
    digitalWrite(12, HIGH);
    MIDI.sendControlChange(68, 127, 2);
    lastRead = millis();
  }

  // HX Stomp Undefined
  if (digitalRead(FS5) == LOW && millis() - lastRead > db) {
    turnLEDOn();
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(12, LOW);
    MIDI.sendControlChange(4, 127, 2);
    lastRead = millis();
  }


  //  Turn led on for 500ms when any switch is pressed. Turn it off after 500ms.
  if (millis() - ledOn > 500 && isLEDOn == true) {
    isLEDOn = true;
    digitalWrite(LEDFS1, HIGH);
    digitalWrite(LEDFS2, HIGH);
    digitalWrite(LEDFS3, HIGH);
    digitalWrite(LEDFS4, HIGH);
    digitalWrite(LEDFS5, HIGH);
  }

}

void turnLEDOn() {
  isLEDOn = true;
  ledOn = millis();
   digitalWrite(LEDFS1, LOW);
   digitalWrite(LEDFS2, LOW);
   digitalWrite(LEDFS3, LOW);
   digitalWrite(LEDFS4, LOW);
   digitalWrite(LEDFS5, LOW);

}

Hi,
You can attach your files to you post and they will be placed in your post by the forum editor.
OPs picture.


Sorry but Fritzy pictures do not show enough information that a proper schematic would.
A circuit diagram would be helpful, can you please draw and post a copy showing parts and pin labels.

Thanks.. Tom.. :slight_smile:

Hi,

Meanwhile I have solved the issue with this code, but I wonder if there is a different / more elegant way of doing this. I am very, very new at this, but it will def not be my last project!

What did you have to do to fix your problem?
It may help others who look a these threads with similar symptoms.

Tom.. :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.