Pages: [1]   Go Down
Author Topic: button counting  (Read 472 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how do i do a "button pressed" counter?

i'm using the PSX2 controller and would like to make my arduino have some lights on it, but not sure on the programming...

basically i want  the cross, triangle, square and circle to each have a pair (poss 2 pairs) of leds...
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
how do i do a "button pressed" counter?
Code:
int buttunPressedCount = 0;
Or 3 or 9 or -17...

Quote
i'm using the PSX2 controller
To push the switches?

Quote
and would like to make my arduino have some lights on it,
No, wait, you are using the PSX2 controller to install the LEDs?

Quote
basically i want  the cross, triangle, square and circle to each have a pair (poss 2 pairs) of leds...
What cross? What triangle? What square? What circle?
Logged

Netherlands
Offline Offline
Full Member
***
Karma: 0
Posts: 123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or do you mean button basics like the one in the arduino community?
Code:
/*
  Button
 
 Turns on and off a light emitting diode(LED) connected to digital  
 pin 13, when pressing a pushbutton attached to pin 2.
 
 
 The circuit:
 * LED attached from pin 13 to ground
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 
 
 created 2005
 by DojoDave <http://www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);    
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {    
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Moderator edit: CODE TAGS
« Last Edit: March 05, 2012, 06:59:33 am by AWOL » Logged

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

bad explaination...

i have basically got an arduino mega attached to a wireless reciever and servo output.... the board is inside a remote controlled car


voila

and i want to put headlighs and brake lights in the car...

on the wireless controller i have a cross, triangle, square and circle buttons, i would like to use them as push buttons to controll the LEDs
Logged

Netherlands
Offline Offline
Full Member
***
Karma: 0
Posts: 123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why is the code posted above not working for you than? You asked about an input that is high (controller) and it should make an output high (leds)?
it sounds like the button example
What am i missing here?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
on the wireless controller i have a cross, triangle, square and circle buttons, i would like to use them as push buttons to controll the LEDs
So, what is it you need to count?
Logged

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

the buttons only work when pressed, so i want to press it once and the LEDs stay on and press again and the LEDs turn off, then it resets
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the buttons only work when pressed, so i want to press it once and the LEDs stay on and press again and the LEDs turn off, then it resets
So, on the Arduino, you need to detect when the switch transitions from not pressed to pressed. When that happens, increment a variable.

When the value in the variable is odd, do one thing. When it is even, do another.

POST YOUR CODE!
Logged

Pages: [1]   Go Up
Jump to: