Go Down

Topic: Ok, how to bring it all together? (Read 1 time) previous topic - next topic

wildbill

Stick with it - you've made some rapid progress & you're bound to want to tweak the project later, so better if you really understand how it works yourself.

Here be dragons though:
Code: [Select]

  if(buttonState != LOW)
    {
    digitalWrite(buttonPin, HIGH);
    if(state == 0); // {
    state = 0;
    // {
    else
      state = state + 1;
    }


It doesn't compile, but you knew that. You have an extraneous semicolon after if(state==0). However, even with that gone, state starts at zero and this if test makes sure that it never changes, so you never see anything on the LCD. Add a section for case 0 to your switch statement below that does put some (any) message on the LCD, just so you can see it's doing something. Your comments say you're pulsing an led, but you're using the pin that the button is attached to.

Try moving your state changing stuff inside the button pressed checking if. Something like this:
Code: [Select]

  if (buttonState != lastButtonState)
    { // compare the buttonState to its previous state
    if (buttonState == HIGH)  // if the state has changed, increment the counter
      {
      buttonPushCounter++;
      if (buttonPushCounter % 4 == 0)
        { // turns on the LED every four button pushes 
        digitalWrite(ledPin, HIGH);
        state = (state + 1) % 6; //fourth button push, increment state, wrap after 5
        }
      else 
        { 
        digitalWrite(ledPin, LOW);
        }
      }     
    }


It will still be problematic until you add some debounce logic, but I think that will at least allow you to change what the LCD shows.

phreaknes

the bracket thing is whats killing me. I spend most of my time trying to figure it out, as you can see with limited success. I'll try your code when I get home. I hope this gets me closer to the finish line.

Go Up