I am trying to make a remote which controls a motor speed based on the angle of an accelerometer. I am using ArduBlock as I am a newbie to programming. I have it printing out the angle of the sensor, and sending the proper signal to the motor board, but want to pause the printing unless there has been a change in the angle. I want to avoid the scroll. I would also like to take the 'delay' command out if there is a way to do so.
How do I make it print the received value ONLY if it is different from the previously received value while still ensuring the control voltage is fed to the motor board?
Thank you for your help!
int _ABVAR_1_XAxis = 0 ;
void setup()
{
pinMode( 12 , OUTPUT);
Serial.begin(9600);
_ABVAR_1_XAxis = 0 ;
}
void loop()
{
_ABVAR_1_XAxis = constrain( map ( analogRead(1) , 245 , 420 , -90 , 90 ) , -90 , 90 ) ;
analogWrite(12 , map ( _ABVAR_1_XAxis , -90 , 90 , 0 , 255 ) );
if (( ( ( _ABVAR_1_XAxis ) >= ( -10 ) ) && ( ( _ABVAR_1_XAxis ) <= ( 10 ) ) ))
{
analogWrite(12 , 128);
Serial.print("Straight");
Serial.print(" ");
Serial.println();
delay( 1000 );
}
if (( ( _ABVAR_1_XAxis ) > ( 10 ) ))
{
Serial.print("Turning Right");
Serial.print(" ");
Serial.print(_ABVAR_1_XAxis);
Serial.print(" ");
Serial.println();
delay( 250 );
}
else
{
if (( ( _ABVAR_1_XAxis ) < ( -10 ) ))
{
Serial.print("Turning Left");
Serial.print(" ");
Serial.print(_ABVAR_1_XAxis);
Serial.print(" ");
Serial.println();
delay( 250 );
}
}
}