Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: I need help with States and buttons in my code on: January 09, 2013, 08:10:54 pm
Ok, I redid a bunch of things based on what I was told by you guys, and this is the result:
Quote
#include <Bounce.h>

int ledPins[] = {2,3,4,5,6,7,8,9,10};
int buttonPin = 11;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;

void setup()
{
  for(int i = 0; i < 9; i++){
  pinMode(ledPins, OUTPUT);   }
  pinMode(buttonPin, INPUT);
}
  
void loop()
{
  buttonState = digitalRead(buttonPin);
  digitalRead(lastButtonState);
  if (buttonState == lastButtonState) {
    buttonPushCounter++;
  }
  else {}
  if (buttonPushCounter == 1) {
//program 2
  }
  else {
//program 1
  }
}

and it still doe'n't work.
I honestly don't know how to make all this work as I am noobish at programming.
And Larry, I thought including the bounce library fixed that?
2  Using Arduino / Programming Questions / I need help with States and buttons in my code on: January 08, 2013, 09:01:40 pm
I have a 3 x 3 led matrix with my led pins 2-10 and a button on 11, and variable resistor on Analog 0. I am trying to fit 5 programs into one, and it switches between them on a button press. this is my code so far:
Quote
#include <Bounce.h>

int ledPins[] = {2,3,4,5,6,7,8,9,10};
int buttonPin = 11;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;

void setup()
{
  for(int i = 0; i < 9; i++){
  pinMode(ledPins, OUTPUT);   }
  pinMode(buttonPin, INPUT);
}
  
void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == lastButtonState) {
    if (buttonState = HIGH) {
  buttonPushCounter++;
//program 1
  } }
  else {
//program 2
  }
}


my program will only switch to the second program when the button is held down, and i don't know how to add my other 3. Please help me!
Pages: [1]