Is this programma correct

Can someone help me, is this a working Arduino program, I use this to make it work via Mit App Inventer, when I start the bluetooth the servos go to 90 degrees and then it's over, the bluetooth red lamp always flickers slowly so is this still connected

#include <Servo.h>

Servo servo1;
Servo servo2;

void setup() 
{
Serial.begin(9600);
servo1.attach(6); //servo 1
servo1.write(90);
servo2.attach(7); //servo 2
servo2.write(90);

}

void loop() {
if (Serial.available() >= 2 )//2
{
unsigned int a = Serial.read();
unsigned int b = Serial.read();
unsigned int val = (b * 256) + a;
if (val >= 0 && val <= 180) // servo 1
{
val=map(val,0,180,180,0);
servo1.write(val);
}
else if (val >= 1000 && val <= 1180) // servo 2
{
val=map(val,1000,1180,1180,1000);
servo2.write(val-1000);
}
//delay(25);
}
}

@Sembot, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

First test the Arduino sketch with serial monitor; once that works, you can sort the Android app out.

That's a fancy/expensive way of doing

val = 2180 - val;

I tried via monitor but it doesn't work
I type "a 50" or " a " or " 1 " all this doesn't work

What is the serial monitor line ending?

new line

And the hex code for newline is . . ?

i don't know this i thought it was the bottom setting of the monitor you are asking sorry

I'm trying to get you to think how your sketch will deal with unexpected characters, like newline.

I think type enter but I actually do not know

So I assume the software is ok , which was my question , but I still don't know how to use this in monitor mode

I realise that you're using binary data; that is something serial monitor can not send. Sorry for putting you on the wrong foot.

Other terminal programs (e.g. Realterm under Windows) can send binary data.

Thanks for the answer , what do I have to change to make it work via monitor mode , can someone help me with that

Than it will not work with your app anymore. Rather install a decent terminal program. Be aware that only one application can have a serial port open; if another terminal program has the port open, you can not upload.

But if you go text-based, have a look at the examples in Robin's Serial Input Basics - updated.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.