Hey guys!
I'm new here and using arduino.
I'm having troubles with my code, I have to switches, one does two thing and the other those just one thing. And what I want is that when I'm using the second switch, the first one stops....
I really have no clue how to do it...
Can someone help?
void setup()
{
pinMode (15, INPUT_PULLUP); //external switch baro/differential
lcd.begin(20, 4);
Wire.begin();
Serial.begin(115200);
if (digitalRead(15)){ // if switch in Baro mode
lcd.print("Sensor+Laser Tester ");
lcd.setCursor(0, 1);
lcd.print("Baro Sensor Init");
lcd.setCursor(0, 2);
lcd.print(" in progress");
lcd.setCursor(0, 3);
lcd.print("LM Design ");
delay (2000);
//Serial.println();
if (barometricSensor.init()) {
//Serial.println("Barometric sensor initialization succeeded!");
barometricSensor.enableSensor(Sodaq_LPS22HB::OdrOneShot);
lcd.setCursor(0, 2);
lcd.print(" Success");
delay (2000);
}
else {
//Serial.println("Barometric sensor initialization failed!");
lcd.setCursor(0, 2);
lcd.print("Sensor init failed ");
delay (1000);
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("Going to laser mode ");
Laser = 1;
delay (2000);
LaserSetup();
}
//Serial.println("Done with setup!");
}else{ // if switch in diff sensor mode
lcd.print("Sensor+Laser Tester ");
lcd.setCursor(0, 1);
lcd.print("Diff Sensor Init");
lcd.setCursor(0, 2);
lcd.print(" in progress");
lcd.setCursor(0, 3);
lcd.print("LM Design ");
delay (1000);
//DiffPressSetup();
//Serial.println();
}
Serial.begin(9600);
pinMode(button, INPUT_PULLDOWN);
Wire.begin();
Serial.begin(9600);
if(digitalRead(9)){
lcd.print("Accel/Mag Test");
lcd.setCursor(0, 1);
lcd.print("");
lcd.print("Use Mag Sensor on X/Y axes");
lcd.setCursor(0, 3);
delay(2000);
LSM303();
} else {
lcd.clear();
}
}
void loop()
{
if (Laser == 1){
ReadLaser();
}
else {
if (digitalRead(15)) {
Serial.println ("EnteredBaro");
BaroPress();
}
else{
Serial.println ("EnteredDiff");
DiffPress();
}
if (digitalRead(9)){
Serial.println("EnteredAcc/Mag");
Accelsensor();
}
}
delay(900);
}
This is the code