I need help, its for tomorrow!

its me again, and i need to fix this, asap, the vid showed me a lot of what i need, but i cant get it to work, please help

const byte numInputs = 4;
const byte inputPins[numInputs] = {A0, A1 ,A2, A3};

const byte numSteps = 7;
const byte steps[numSteps] = {0, 4, 3, 2, 3, 1, 2};

const byte ledPins[numSteps] = {2, 4, 7, 8, 9, 12, 13};
const byte lockPin = 5;


bool lastInputState[] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH} ;
int currentState = 0;


unsigned long lastDebounceTime = 0;
unsigned long DebounceDelay = 50;


void setup() {
  
  for(int i=0; i< numInputs; i++) {
    pinMode(inputPins[i], INPUT_PULLUP);
  }
  for(int i=0; i< numSteps; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
  
  pinMode(lockPin, OUTPUT);
  digitalWrite(lockPin, HIGH);
  

  
  
}

void loop() {
  if(currentInputState == LOW && lastInputState == HIGH) {
        
        if(steps[currentState] == i) {
          currentState++;
        }
      }
        
        else {
          currentState = 0;
          Serial.println("Not Right! Start From Scratch");
        }
      }
      
      lastInputState[i] = currentInputState;
    }
  }

  
  if(currentState = numStates) {
    onSolved();
  }
  
  for(int i=0; i<numStates; i++) { 
    digitalWrite(ledPins[i], (i < currentState ? HIGH : LOW);
                 }
                 }               
                                 
void onSolved() {
  
  

                 
  digitalWrite(lockPin, LOW);
                 while(true){
                   for(int i=0; i<numSteps; i++){
                     digitalWrite(ledPins[i], HIGH);
                     delay(100);
                   }
                   delay(100);
                   for(int i=0; i<numSteps; i++){
                     digitalWrite(ledPins[i], HIGH);
                     delay(100);
                   }
                 }
}      

For help, please read and follow the instructions in the "How to get the best out of this forum" post, linked at the head of every forum category.

2 Likes

how do i get the best out of this forum?

  • You read and then follow the forum’s guidelines.

  • We don’t see a Sketch Preamble, we see no schematic, there are no comments in the sketch. :roll_eyes:

2 Likes

Your code doesn’t compile or work for several reasons:

  1. currentInputState is not defined**
    You are referencing currentInputState, but it is neither defined nor initialized in the loop.
  2. lastInputState[] is incorrectly defined**
    You're trying to track the last state for each input, but the array has 7 elements instead of 4 — it should match numInputs.
  3. if (currentState = numStates)**
    = is assignment, not comparison. It should be ==.
    Also, numStates is not defined — you probably meant numSteps.
  4. Missing input monitoring logic**
    There’s no for loop to check inputs or it's placed incorrectly.
  5. Error in LED update loop**
    You're using the wrong variable (numStates) in the loop, and there's also a brackets mismatch.

i should do that

By reading and following the directions in the "How to get the best out of this forum" post.

2 Likes

if its not a bother, i need help fixing it, cause i dont even have the shell cut and im tight rn, since its 6:34 pm where i am, and its PVC im cutting

ah...

Show us the picture of a hand-drawn wiring diagram. Post ALL code in code tags, and post all serial output also in code tags.
Now tell us what you expected and what actually happened.

1 Like

Not an Arduino problem, but you should have no trouble finishing that task by tomorrow.

1 Like

i know, i just need the code to work, and its not working

Use the translate function on Google or DuckDuckGo to translate into English. I can't ready whatever that is you tried to write.

Where did you find the code? Did you format it and see the many syntax errors?

  1. Learn about "=" versus "=="
  2. You must be in the scope of a variable to use it... for example... i... you lost track of which one you were using.
  3. You also got lost with overuse of "states" and "steps" Verify them.

Fix these and it compiles.

idk how to do that, but i want that code to function like in those escape rooms, a sequence of sorts

4 buttons

7 LEDs

i got the thing up, i just need the code to work properly

1 Like

Draw a picture.

1 Like

7 year old youtube vid

will do

i think thats for mutliple scopes and not just one, since its multiple leds working at once

figures, i got lost myself on the vid, but thats besides the point

its not that i dont know how to code, i just needed this type of code, since this is higher level than what im familiar with

idk how to do that

Use a translator to translate what you write into English.

Draw...

Scope depends on where you define a variable. When you define it outside all functions, it is global, and can be used anywhere. When you define a variable inside a function, it is local to the function. When you define a variable inside a condition, it is local to the condition. You can not use locally defined function outside its scope.

And I don't know how to help you.

1 Like