Go Down

Topic: display text as particular button is pressed? (Read 312 times) previous topic - next topic

Sayem5310

i want to use multiple tactile button to display different text as a particular button is pressed.

the problem is the text is strobing and its changing automatically as i plug a jumper in the pins.

Code: [Select]
// This constant won't change:
const int led1 = 8;
const int led2 = 9;
const int led3 = 10;
const int led4 = 11;

// Variables will change:
int ButtonState = 0;
int ButtonState1 = 0;
int ButtonState2 = 0;
int ButtonState3 = 0;// current state of the button
int oldButtonState = 0;
int oldButtonState1 = 0;
int oldButtonState2 = 0;
int oldButtonState3 = 0; // previous state of the button


#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
  pinMode(led1, INPUT);
    pinMode(led2, INPUT);
      pinMode(led3, INPUT);
      pinMode(led4, INPUT);
    digitalWrite(led1, LOW);
     digitalWrite(led2, LOW);
      digitalWrite(led3, LOW);
       digitalWrite(led4, LOW);   

 
 Serial.begin(9600);
  lcd.begin(16, 2);
 
 
}

void loop(){
{
 
ButtonState = digitalRead(led1);

//### The Button
  if (ButtonState != oldButtonState) {
    if (ButtonState == HIGH) {
lcd.clear();
   lcd.setCursor(0,1);
     delay (10);
     lcd.print("relay 1");}
    }
    delay(30);
    }
 
 {

ButtonState1 = digitalRead(led2);

//### The Button
  if (ButtonState1 != oldButtonState1) {
    if (ButtonState1 == HIGH) {
lcd.clear();
   lcd.setCursor(0,1);
     delay (11);
     lcd.print("relay 2   ");}
 
    }
 }
 
{

ButtonState2 = digitalRead(led3);

//### The Button
  if (ButtonState2 != oldButtonState2) {
    if (ButtonState2 == HIGH) {
lcd.clear();
   lcd.setCursor(0,1);
     delay (11);
     lcd.print("relay 3");}
   
    }


{
ButtonState3 = digitalRead(led4);

//### The Button
  if (ButtonState3 != oldButtonState3) {
    if (ButtonState == HIGH) {
lcd.clear();
   lcd.setCursor(0,1);
     delay (11);
     lcd.print("relay 4");}
   
  }
}
}

Paul_KD7HB

Of course things are changing. You have "floating pins". Please google that! Your pins must be permanently tied to either 5 volts or to ground through resistors to avoind what you are seeing. If your program does not read the pins, then no one cares if the pin is floating.

I hope you are not messing around with jumper wires while the Arduino is powered up. Are you using jumper wires in place of switches?

A schematic of your wiring would certainly make it easier to provide help.

Paul

Go Up