i am using Zumo kit for my experiments, here i am trying to control my Zumo Robot with an accelerometer. i get input from accelerometer and check for the conditions. i used two "if" statements the problem is only one if statement (second if) is executing and other one is skipped by the machine. i inserted the code let me know the problem
#define LED_PIN 13
#include <ZumoMotors.h>
int turnright;
int x;
int turnleft;
ZumoMotors motors;
const int threshold1 = 280;
const int threshold2 = 300;
void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
}
void loop()
{
x=analogRead(A0);
turnright=map(x,310,370,0,50);
turnright=constrain(turnright,0,50);
turnleft=map(x,310,249,0,50);
turnleft=constrain(turnleft,0,50);
{if (x <= 280)
{
motors.setSpeeds(50,100);
}
if (x >= 300)
{
motors.setSpeeds(100,50);
}
else {
motors.setSpeeds(50, 50);
}
}
Serial.print(x);
Serial.print('\t');
Serial.print(turnright);
Serial.print('\t');
Serial.print(turnleft);
Serial.print('\t');
Serial.println();
}