hi guys
I m working on a sound sensitive security camera project that calculates the angle of audio signal using visual C#. I'm sending angle information via serial to Arduino.
angle information contains negative and positive values. please refer to the picture attached. I wants rotate my servo motor. I'm kind of confused since there is negative angles. can someone help me with this please.
I really appreciate it.
thank you!

Make your reference 90 degrees. Add the angle to the reference. Then the servo will move from 45 to 135 degrees.
thank you very much for giving me an idea how to do it. I'm kind of new to Arduino and this is the code i wrote with my understanding,
#include<Servo.h>
Servo base;
void setup() {
base.attach(8) ;
base.write(90);
Serial.begin(9600);
}
void loop() {
int val=Serial.parseInt();
if(val!=0)
{
base.write(val);
}
}
i tried and doesn't give me expected result. my code might be wrong. please someone have a look
thank you!
My thinking was more along this line:
#include<Servo.h>
Servo base;
int refAngle = 90;
void setup()
{
base.attach(8) ;
base.write(refAngle);
Serial.begin(9600);
}
void loop()
{
int val = Serial.parseInt();
if (val != 0) // why are you doing this test?
{
base.write(refAngle + val);
}
}
I think that you should add a Serial.available test as there is no point reading serial if nothing is there. I would recommend that you read Robin2's serial input basics thread to see how to more properly read from the serial port.
thank you very much for fixing my code. I am going to follow the thread that you referred. you guys are awesome !