   lcd.print("                ");
 
 }
+// Motor control
+
+void switchOffMotor() {
+  analogWrite(PWMA,0);
+  publishDebug("Switching off motor");
+  lcdStatus("Motor off");
+}
+
+void tiltTray() {
+  analogWrite(PWMA,500);
+  publishDebug("Tilting tray");
+  lcdStatus("Tilting tray");
+}
 
 // Sensors
 
 void motorSwitchLeftActivated() {
   state = MOTOR_SWITCH_DETECTED;
   motorSwitchDetected = MOTOR_SWITCH_LEFT;
-}
-
-void motorSwitchRightActivted() {
+//  delay(100);
+}
+
+void motorSwitchRightActivated() {
   state = MOTOR_SWITCH_DETECTED;
   motorSwitchDetected = MOTOR_SWITCH_RIGHT;
-}
-
-void motorSwitchActivated() {
+  //delay(100);
+}
+
+// void timerSwitchActivated() {
+//   state = TIMER_SWITCH_ACTIVATED;
+// }
+
+void motorSwitchAction() {
   state = PUBLISHING_ENVIRONMENT_EVENT;
+  switchOffMotor();
   if (motorSwitchDetected == MOTOR_SWITCH_LEFT) {
     lcdStatus("Switch Left");
     publishDebug("Left Motor Switch Detected");

    lcdStatus("Switch Right");
    publishDebug("Right Motor Switch Detected");
  }
  delay(1000);
  digitalWrite(BUILTIN_LED, LOW);
  state = IDLE;
}

  //publishDebug("Initialising Motor");
  initMotor();
  initSwitches();
  //publishDebug("Initialising Timers");
  //initTimers();
  initTimers();
//----------------- wifi_set_sleep_type(LIGHT_SLEEP_T);
//----------------- gpio_pin_wakeup_enable(GPIO_ID_PIN(2),GPIO_PIN_INTR_HILEVEL);
