hello, am making a small elevator project where the micro-controller should read combination of digital input pins to know where the elevator is and if any button has been pressed. The digital information are provided from an external circuit using an 74ls148 encoder and it works fine when i tested it seperately. when connected to the arduino uno, the micro controller is able to read the data from the encoder, but when the encoded data is changed and the micro controller reads the input pins again in the loop, it get the same previous input data, even if i disconnect the encoder, it read same previous data which is not true. How can i make the arduino uno read the new data on the input pins when the loop starts again?
Below is the code for the main loop i am using.
void loop(){
digitalWrite(A5, LOW);
digitalWrite(A4, HIGH);
REINPUT:
int ThisLevel=LReader(); //LReader reads pins 2,3,8 and return and integer
int Selection=SReader(); //RReader reads pins 5,6,7 and return and integer
int SecondSelect;
if (ThisLevel==6){
Serial.println("Elevator not in position");
digitalWrite(A5, HIGH);
// tone(9,2000,1000);
delay(1500);
}
else if(Selection==6){
goto REINPUT;
}
else{
SayActivated();
int FirstSelect=SReader();
int tempselect;
if(FirstSelect==4 || FirstSelect==5){
if(FirstSelect==5){
Serial.println("Emergency button activated");
digitalWrite(A5,HIGH);
return;
}
Door();
goto REINPUT;
}
else if(FirstSelect=Selection){
Door();
goto REINPUT;
}
else{
SayLevelSelected(FirstSelect);
for (int counter=0;counter<=199;counter++){
SecondSelect=SReader();
delay(500);
if(SecondSelect==FirstSelect){
SayCancelled();
delay(500);
goto REINPUT;
}
else {tempselect=FirstSelect;
}
}
int Select=FinalSelect(tempselect);
int w=Compare(Select,ThisLevel);
MotorExecute(w);
Deactivate();
}
}}
bhavish009:
hello, am making a small elevator project where the micro-controller should read combination of digital input pins to know where the elevator is and if any button has been pressed. The digital information are provided from an external circuit using an 74ls148 encoder and it works fine when i tested it seperately. when connected to the arduino uno, the micro controller is able to read the data from the encoder, but when the encoded data is changed and the micro controller reads the input pins again in the loop, it get the same previous input data, even if i disconnect the encoder, it read same previous data which is not true. How can i make the arduino uno read the new data on the input pins when the loop starts again?
Below is the code for the main loop i am using.
You said it reads same data even when disconnected so how does it changes?
Put this in it own loop to test it before you descramble your spaghetti code.
do{
int ThisLevel=LReader(); //LReader reads pins 2,3,8 and return and integer
int Selection=SReader(); //RReader reads pins 5,6,7 and return and integer
Serial.print(ThisLevel);
Serial.print(Selection);
delay(2000);
}while(1);
After that remove the do / while and try this:
Selection = 6;
and some other Serial to track you code - does it really stays in Selection == 6 "loop" back to the label?
int SecondSelect;
if (ThisLevel==6){
Serial.println("Elevator not in position");
digitalWrite(A5, HIGH);
// tone(9,2000,1000);
delay(1500);
}
else if(Selection==6){
goto REINPUT; // test this first setting Selection = 6
}
else{
SayActivated();
int FirstSelect=SReader();
int tempselect;
if(FirstSelect==4 || FirstSelect==5){
if(FirstSelect==5){
Serial.println("Emergency button activated");
digitalWrite(A5,HIGH);
return;
}
Door();
goto REINPUT;
}
else if(FirstSelect=Selection){
Door();
goto REINPUT;
}
else{
SayLevelSelected(FirstSelect);
Sorry i did not put the complete code.
i am posting the part where the error is occuring below. The arduino reads the input pins only once, and keeps reading the same input when the loop restarts and the combination on the input pins have changed.
Your digitalReads are outside of the loop. They are read only once when the chip powers up, not every time loop iterates, so obviously you'll get the same value you store in your ints.