Jump to content
Samil

Two interrupts for the same pin

Recommended Posts

Hello everyone.

I am trying to design a prototype for a fairly simple motor controller using a Tiva EK-TM4C1294XL board and Energia.

I have a 20x2 char LCD, 5 buttons and 3 output signals.

Buttons are momentary switches for, respectively,

1) going up while pressed and stopping and waiting in standby when released

2) going down while being pressed and stopping and waiting in standby when released

3) going to bottom when pressed once

4) going to top when pressed once and

5) stopping due to emergency (stop while being pressed and standby when released.

I am not going to include the 3 output signals into the discussion because they are easy to handle later.

For the 1st and 2nd buttons, I thought it would be best to use the interrupts being fired at RISING and FALLING edges, so that I would start running the motor when the putton is pressed and stop it when the button is released.

However, my problem is that when I press and keep pressed the 1st, 2nd and 5th buttons, my code prints "READY" on my LCD, which means standby, as if the button is released.

Can somebody please explain me what I am doing wrong? Below is my poor code.

#include <LiquidCrystal.h>
#define RS 31
#define EN 32
#define D4 33
#define D5 34
#define D6 35
#define D7 36
#define asagi 42
#define yukari 43
#define tamasagi 44
#define tamyukari 45
#define acil 46
	#define upled 6
#define pwmenable 7
#define downled 8
int i=0;
int j=5;
	LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
	void setup() {
  
  pinMode(upled, OUTPUT);
  pinMode(pwmenable, OUTPUT);
  pinMode(downled, OUTPUT);
  
  pinMode(asagi, INPUT_PULLUP);
  pinMode(yukari, INPUT_PULLUP);
  pinMode(tamasagi, INPUT_PULLUP);
  pinMode(tamyukari, INPUT_PULLUP);
  pinMode(acil, INPUT_PULLUP);
	  
    lcd.begin(20, 2);
    lcd.setCursor(0, 0);
    lcd.print("01234567890123456789");
    lcd.setCursor(0, 1);
    lcd.print("01234567890123456789");
  delay(1000);
  lcd.clear();
  digitalWrite(upled, LOW);
  digitalWrite(downled, LOW);
  analogWrite(pwmenable, 255);
  attachInterrupt(asagi, startgodown, FALLING);
  attachInterrupt(asagi, godownstop, RISING);
  attachInterrupt(yukari, startgoup, FALLING);
  attachInterrupt(yukari, goupstop, RISING);
  attachInterrupt(tamasagi, gobottom, FALLING);
  attachInterrupt(tamyukari, gotop, FALLING);
  attachInterrupt(acil, startemergency, RISING);
  attachInterrupt(acil, emergencyend, FALLING);
}
	void startgodown()
{
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("ASAGI"); // Go Down
}
void godownstop()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("HAZIR1"); // Ready1
}
void startgoup()
{
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("YUKARI"); // Go Up
}
void goupstop()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("HAZIR2"); //Ready2
}
void gobottom()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("TAM ASAGI"); //Go to bottom
}
void gotop()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("TAM YUKARI"); // Go to top
}
void startemergency()
{
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("ACIL"); // Emergency
  lcd.setCursor(0, 1);
  lcd.print("DURUM");
}
void emergencyend()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("HAZIR3"); //Ready3
}
	
void loop() {
  // do nothing
  
}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...