Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



loop1 & loop2 not r...
 
Share:
Notifications
Clear all

[Solved] loop1 & loop2 not running by pressing relevant buttons

2 Posts
1 Users
0 Reactions
1,109 Views
(@Anonymous)
Joined: 1 second ago
Posts: 0
Topic starter  
const int LED_1 = 9; //Status of button_N remains on
const int LED_2= 8; //Status of button_R remains on
const int BUTTON_N =2;
const int BUTTON_R =3;
const int BUTTON_1= 4; //activate RL_1
const int BUTTON_2= 5; //activate RL_2
const int RL_1 =6;
const int RL_2 =7;
int BUTTONstate1,BUTTONstate2; 
 
int buttonStateN,buttonStateR;

int lastPin1State,lastPin2State;
int lastN,lastR;
void setup()
{
  Serial.begin(115200);
  pinMode(LED_1, OUTPUT);
  pinMode(LED_2, OUTPUT);
  pinMode(BUTTON_N, INPUT);
  pinMode(BUTTON_R, INPUT);
  pinMode(BUTTON_1, INPUT);
  pinMode(BUTTON_2, INPUT);
  pinMode(RL_1, OUTPUT);
  pinMode(RL_2, OUTPUT);
   
}

void loop1()
{
  digitalWrite(LED_1, HIGH);
  digitalWrite(LED_2, LOW);
  //BUTTONstate1 = digitalRead(BUTTON_1);
  int pinNState = digitalRead(BUTTON_1);
  int pinRState = digitalRead(BUTTON_2);
  if (pinNState == HIGH && lastN == LOW && pinRState == LOW) 
  //if (BUTTONstate1 == HIGH)
  {
    digitalWrite(RL_1, HIGH);
  } 
  else{
    digitalWrite(RL_1, LOW);
  }
  //BUTTONstate2 = digitalRead(BUTTON_2);
  //if (BUTTONstate2 == HIGH)
  if (pinRState == HIGH && lastR == LOW && pinNState == LOW) 
  {
    digitalWrite(RL_2, HIGH);
  } 
  else{
    digitalWrite(RL_2, LOW);
  }
  lastN = pinNState;
  lastR = pinRState;
   delay(10);
}

void loop2()
{
  digitalWrite(LED_2, HIGH);
  digitalWrite(LED_1, LOW);
   //BUTTONstate1 = digitalRead(BUTTON_1);
  //if (BUTTONstate1 == HIGH)
  int pinNState = digitalRead(BUTTON_1);
  int pinRState = digitalRead(BUTTON_2);
  if (pinNState == HIGH && lastN == LOW && pinRState == LOW) 
  {
    digitalWrite(RL_2, HIGH);
  } 
  else{
    digitalWrite(RL_2, LOW);
  }
  //BUTTONstate2 = digitalRead(BUTTON_2);
  //if (BUTTONstate2 == HIGH)
  if (pinRState == HIGH && lastR == LOW && pinNState == LOW) 
  {
    digitalWrite(RL_1, HIGH);
  } 
  else{
    digitalWrite(RL_1, LOW);
  }
   lastN = pinNState;
   lastR = pinRState;
   delay(10);
  
}


void loop()
{
  Serial.print( "buttonStateN = ");
  Serial.print( buttonStateN );
  Serial.println();
   int pin1State = digitalRead(BUTTON_N);
   int pin2State = digitalRead(BUTTON_R);
  if (pin1State == HIGH && lastPin1State == LOW && pin2State == LOW) 
  {
    
      
      loop1();
  } 
  Serial.print( "buttonStateR = ");
  Serial.print( buttonStateR );
  Serial.println();
    if (pin2State == HIGH && lastPin2State == LOW && pin1State == LOW) 
  {
      loop2();
    
  }
  lastPin1State = pin1State;
  lastPin2State = pin2State;
   
      
    }

   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0

   
ReplyQuote
Share: