Pages: 1 [2]   Go Down
Author Topic: Ok, how to bring it all together?  (Read 1380 times)
0 Members and 1 Guest are viewing this topic.
New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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:
  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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2]   Go Up
Jump to: