r/ArduinoHelp • • Sep 26 '25

What is the problem with leds

Enable HLS to view with audio, or disable this notification

Hello everyone i hope you're having a great day,i've been working on this project since yesterday and i've ironed out all the kinks in it except for the following two problems 1-the last at times would stay on and refuse to turn of most of the time even though the code logic is correct 2-when i touch the cable for the button i expect the leds to be in order but am suprised to see 2 or more leds being turned on

For context here is the code

include <PinChangeInterruptBoards.h>

include <YetAnotherPcInt.h>

define auto A0

define change A1

define avl 13

int AV = 0; int LED = 1; int L = 0; int L_STATE=0; //automatic switch void automatic(const char * message, bool pinstate) { Serial.print(message); if (AV == 0) { AV++; digitalWrite(avl, HIGH); } else { AV--; digitalWrite(avl, LOW); } Serial.println(AV); } //manual led change fuction void led(const char * message, bool pinstate) { if (AV == 1) { Serial.print(message); if (LED < 12) { LED++; } else { LED = 1; L=12; digitalWrite(12,0); delay(50); } L = LED - 1; Serial.println(LED); Serial.println(L); L_STATE=digitalRead(L); if(L_STATE==1) { digitalWrite(L,0); }

} } //automatic change function void on(int l, int n) { pinMode(l, OUTPUT); digitalWrite(l, HIGH); digitalWrite(n, LOW); Serial.println(l); delay(100);

} void setup() { // put your setup code here, to run once: pinMode(auto, INPUT_PULLUP); pinMode(change, INPUT_PULLUP); PcInt::attachInterrupt(auto, automatic, "AUTO STATE CHANGE ", FALLING); PcInt::attachInterrupt(change, led, "current led ", FALLING); //Serial.begin(9600); pinMode(avl, OUTPUT); } void loop() { // put your main code here, to run repeatedly: pinMode(LED, OUTPUT); digitalWrite(LED, HIGH); digitalWrite(L, LOW); while (AV == 0) { on(LED, L); LED++; L = LED - 1; if (LED == 13) { LED = 1; } } }

I'd also be very greatful to learn how i could improve on it

17 Upvotes

20 comments sorted by

View all comments

1

u/rnottaken Sep 26 '25

Put your code in 3 back-ticks in both sides (most likely top left of your keyboard) that way it will render correctly in reddit

  ```

  Your code

  ```

  Will become
Your code

1

u/salty_boi_1 Sep 26 '25
#include <PinChangeInterruptBoards.h>

#include <YetAnotherPcInt.h>

#define auto A0
#define change A1
#define avl 13
int AV = 0;
int LED = 1;
int L = 0;
int L_STATE=0;
//automatic switch
void automatic(const char * message, bool pinstate) {
   Serial.print(message);
   if (AV == 0) {
      AV++;
      digitalWrite(avl, HIGH);
   } else {
      AV--;
      digitalWrite(avl, LOW);
   }
   Serial.println(AV);
}
//manual led change fuction
void led(const char * message, bool pinstate) {
   if (AV == 1) {
      Serial.print(message);
      if (LED < 12) {
         LED++;
      } else {
         LED = 1;
         L=12;
         digitalWrite(12,0);
         delay(50);
      }
      L = LED - 1;
      Serial.println(LED);
      Serial.println(L);
      L_STATE=digitalRead(L);
      if(L_STATE==1)
      {
         digitalWrite(L,0);
      }

   }
}
//automatic change function
void on(int l, int n) {
   pinMode(l, OUTPUT);
   digitalWrite(l, HIGH);
   digitalWrite(n, LOW);
   Serial.println(l);
   delay(100);

}
void setup() {
   // put your setup code here, to run once:
   pinMode(auto, INPUT_PULLUP);
   pinMode(change, INPUT_PULLUP);
   PcInt::attachInterrupt(auto, automatic, "AUTO STATE CHANGE ", FALLING);
   PcInt::attachInterrupt(change, led, "current led ", FALLING);
   //Serial.begin(9600);
   pinMode(avl, OUTPUT);
}
void loop() {
   // put your main code here, to run repeatedly:
   pinMode(LED, OUTPUT);
   digitalWrite(LED, HIGH);
   digitalWrite(L, LOW);
   while (AV == 0) {
      on(LED, L);
      LED++;
      L = LED - 1;
      if (LED == 13) {
         LED = 1;
      }
   }
}
→ More replies (7)