pullup LED

hey Guys

i want to let LED on and off by using 2 button's together (&&) in PULLUP with out Delay. can any one help me with some code .or idea

Have you tried asking here ?

Hi, In the IDE there is an example in DIGITAL called Button. It will show you how to turn an LED on and off with a button for you to start with.

Tom... :)

hey Tom i did follow the example but they used delay . i mast do it with out delay

Hi,
The button example , where is the delay?

/*
  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);
  }
}

Tom… :slight_smile:

Thx Tom but now the led dont stay on for sometime it going fast from on to off :-)

So, now you have some code you haven’t posted, reading from a switch that is wired some unknown way, and you want us to tell you what is wrong. Doesn’t seem likely, does it?

i did post the code

i do it one more time

/* Debounce

Each time the input pin goes from LOW to HIGH (e.g. because of a push-button press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's a minimum delay between toggles to debounce the circuit (i.e. to ignore noise).

The circuit: * LED attached from pin 13 to ground * pushbutton attached from pin 2 to +5V * 10K resistor attached from pin 2 to ground

  • Note: On most Arduino boards, there is already an LED on the board connected to pin 13, so you don't need any extra components for this example.

created 21 November 2006 by David A. Mellis modified 30 Aug 2011 by Limor Fried modified 28 Dec 2012 by Mike Walters

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Debounce */

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

// Variables will change: int ledState = LOW; // the current state of the output pin int ledState1= LOW ;

int buttonState; // the current reading from the input pin int buttonState1; // the current reading from the input pin

int lastButtonState = LOW; // the previous reading from the input pin int lastButtonState1 = LOW; // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long lastDebounceTime = 0; // the last time the output pin was toggled long lastDebounceTime1 = 0; // the last time the output pin was toggled

long debounceDelay = 50; // the debounce time; increase if the output flickers long debounceDelay1 = 50; // the debounce time; increase if the output flickers

void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(buttonPin1, INPUT_PULLUP); pinMode(ledPin, OUTPUT);

// set initial LED state digitalWrite(ledPin, ledState); }

void loop() { // read the state of the switch into a local variable: int reading = digitalRead(buttonPin); int reading1 = digitalRead(buttonPin1);

// check to see if you just pressed the button // (i.e. the input went from LOW to HIGH), and you've waited // long enough since the last press to ignore any noise:

// If the switch changed, due to noise or pressing: if (reading != lastButtonState) { // reset the debouncing timer lastDebounceTime = millis(); } if (reading1 != lastButtonState1) { // reset the debouncing timer lastDebounceTime1 = millis(); }

if ((millis() - lastDebounceTime) > debounceDelay && (millis() - lastDebounceTime1) > debounceDelay1 ) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state:

// if the button state has changed: if ((reading != buttonState) && (reading1 != buttonState1)) { buttonState = reading; buttonState1 = reading1; // only toggle the LED if the new button state is LOW if (buttonState == LOW && buttonState1 == LOW){ ledState = !ledState; ledState1 = !ledState1; } } }

// set the LED: // digitalWrite(ledPin, ledState1); digitalWrite(ledPin, ledState);

// save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonState = reading; lastButtonState1 = reading1; }

  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(buttonPin1, INPUT_PULLUP);

When numbering variables, either DON'T (use an array instead) or number ALL the variables in a set.

 // if the button state has changed:
    if ((reading != buttonState) && (reading1 != buttonState1)) {
      buttonState = reading;
      buttonState1 = reading1;
      // only toggle the LED if the new button state is LOW
      if (buttonState == LOW && buttonState1 == LOW){
        ledState = !ledState;
        ledState1 = !ledState1;
      }

The comment IS important. Note that it refers to ONE reading. You can NOT combine the change of state of the two pins in one block of code.

You do NOT need three values (reading, buttonState, and lastButtonState) to determine of the current state is different from the previous state of one switch.

  1. pls post your code (in </> code tags)
  2. think about “debouncing” your button(s)

edit:

i did post the code

where and when? I couldn’t see it in this thread, when writing my reply

so how i can combine the change two button? like both of them is LOW then the led on i did also try variables counter ++ for that but still dont work

so how i can combine the change two button? like both of them is LOW then the led on i did also try variables counter ++ for that but still dont work

Both of them IS LOW and CHANGE do NOT go together.

Just what ARE you trying to do?

i want 2 Buttons INPUT_PULLUP with LED . when user click both of them the led going on and then one more click the led going off .no delay

I think this should work. Both buttons must be pressed for the led to come on. The buttons works as toggles in conjunction with the ‘bit’ machine. The controller checks the bits and switches the led on/off according to their state.

#include <Automaton.h>

Atm_button button1, button2;
Atm_controller ctl;
Atm_bit bit1, bit2;
Atm_led led;
Appliance app;

void setup() {
  app.component( led.begin( 4 ) );
  app.component( 
    ctl.begin()
	  .IF( bit1 ).AND( bit2 )
	  .onChange( true, led, led.EVT_ON )
	  .onChange( false, led, led.EVT_OFF )
  );
  app.component( bit1.begin() );
  app.component( bit2.begin() );
  app.component( button1.begin( 2 ).onPress( bit1, bit1.EVT_TOGGLE ) );
  app.component( button2.begin( 3 ).onPress( bit2, bit2.EVT_TOGGLE ) );
}

void loop() {
  app.run();
}

https://github.com/tinkerspy/Automaton/wiki