Hello again, im back with the same fixed code, but nothing happens

its me, but im here because im stumped

i got an extension to my projet, turns out 1/6 students finishing doest look good, so yea, but im actually wondering how to fix or define certain functions, cause i ran this on a arduino simulator, and no luck

any pointers or ideas, if so, whats wrong with it?

i should mention this code gives no errors, so nothing is giving me a negative

#define DEBUG

const byte numInputs = 4;
const byte inputPins[numInputs] = {2, 3, 4, 5};

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

const byte ledPins[numSteps] = {6, 7, 8, 9, 10, 12, 13};
const byte lockPin = A0;


bool lastInputState[] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH} ;
int currentStep = 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);

  #ifdef DEBUG
  Serial.begin(9600);
  Serial.println("Serial Communication Started");
  #endif

  
  
}

void loop() {
  if ( (millis() - lastDebounceTime > debounceDelay)) {
    for(int i=0; 1<numInputs; i++) {
      int currentInputState = digitalRead(inputPins[i]);
      if(currentInputState != lastInputState[i]) {
        lastDebounceTime = millis();
      }
      if(currentInputState == LOW && lastInputState == HIGH) {
        if(steps[currentStep] == i) {
          currentStep++;
          #ifdef DEBUG
          Serial.print(F("Nice, Onto the next step #"));
          Serial.println(currentStep);
          #endif

        }
        else {
          currentStep = 0;
          Serial.println("Not Right! Start From Scratch");
        }

      }
      lastInputState[i] = currentInputState;

    }


  }
  if(currentStep == numSteps) {
    onSolved();
  }
  
  for(int i=0; i<numSteps; i++) { 
    digitalWrite(ledPins[i], (i < currentStep ? 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);
                   }
                 }
}     
  • Tell us what you expect here ?

for(int i=0; 1<numInputs; i++) {

Please flag your post and ask a moderator to move it to the thread where all those errors are being discussed.

And use Autoformat before you post your code.

a7

Then you need to enable all warnings. Go to File -> Preferences and for Compiler Warnings, select "all" and the compiler will tell you your problem.

In file included from sketch\sketch_apr21b.ino.cpp:1:0:
C:\Temp\arduino_modified_sketch_413787\sketch_apr21b.ino: In function 'void loop()':
C:\.../Arduino.h:40:14: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]
 #define HIGH 0x1
              ^
C:\Temp\arduino_modified_sketch_413787\sketch_apr21b.ino:49:57: note: in expansion of macro 'HIGH'
       if (currentInputState == LOW && lastInputState == HIGH) {
                                                         ^~~~

On your other thread, you were asked about having four inputs and it seems you are looking for 5 different numbers

const byte inputPins[numInputs] = {2, 3, 4, 5};

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

Try a combination that might work

const byte numInputs = 4;
const byte inputPins[numInputs] = {2, 3, 4, 5};

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

I had to fix a few other errors which have been brought to your attention already.

There also remain defects perhaps only a perfectionist would notice. I'm not naming any names.

a7

its a function to make the nex press change, i also see a 1 where their should be an i

i dont thow how to do that, 2 weeks in and im still adjusting

woah

  • In the Arduino IDE, use Ctrl T or CMD T to format your code.

done, i also did what blh64 told me

that piece of code might be causing the problem, how do i replace or fix it if it is giving a problem?

Why do you keep starting new threads? It is a waste of everyone's time.

Moderator notified of cross-posting.

mb, im still new to this, so im still working on things, and since its basically new code, i assumed i made a new one each time

thanks, nice fix

Don't thank me, go to your other thread and thank @DaveX who pointed out this mistake 21 hours ago.

Who knows, maybe you would have distinguished yourself and gotten this to fly in time. :expressionless:

a7

possibly, but now i got a macro HIGH on a comparison between pointer and integer, what do i do about that?

Read your code. Look closely. You managed to use arrays and mix them with scalars, but you were not thorough in doing.

Read the error message @blh64 brought up.

And I know you're en charrette, but here's a pro tip: single letters make lousy identifiers.

I use ii for very local stuff like for loops, one of which should replace the while loop found in onSolved() BTW, because ii is never 1 l I | ! or you get the idea.

They make lousy targets for searching, too.

Code sings here with all you have read applied. I added a button instead of changing the combo pattern, which was mostly easy, your sketch is amenable to changes, very nice.

a7

where do i put this possible solve ii?

i get that same error when i did what bro told me, i put a [i] on lastInputState, but that just instantly activated 1 to 4, so i removed it

edit: its supposed to be there, its just making the leds crazy, so its possibly not the problem

I think that is all I changed.

But just now I see why this might not work, but see if it is what you did, and see if it works as a transplnat. Please don't just transplant it blindly. You will hurt someone's feelings, again not naming names.

You will note the addition of the printing. And were you getting four or N Nice, "Onto the next step #" or repeatint resets or what? The more you say the better I can laser my focus as the sketch is very close TBH I was mostly tinkering about the alleged defects since I had built the thing why not have fun?

Anyway, this:

    for (int i = 0; i < numInputs; i++) {
      int currentInputState = digitalRead(inputPins[i]);
      if (currentInputState != lastInputState[i]) {
        lastDebounceTime = millis();
      }
      if (currentInputState == LOW && lastInputState[i] == HIGH) {

        Serial.print("            pressed "); Serial.println(i);
        if (steps[currentStep] == i) {
          currentStep++;
#ifdef DEBUG
          Serial.print(F("Nice, Onto the next step #"));
          Serial.println(currentStep);
#endif
        }
        else {
          currentStep = 0;
          Serial.println("Not Right! Start From Scratch");
        }
      }
      lastInputState[i] = currentInputState;
    }

HTH

a7

noted

glad to hear you are having fun, im having fun learning to refine this code with experts, or at least people with higher experience than me, i love learning things like these