Go Down

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


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;
    // {
      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
      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
        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.


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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131