Hello everyone...
I'm trying to control 2 servo, one will keep sweeping automatically while the others will change position when i push my transmitter...
I know this need to use interrupt but i cant really understand how to write the program...
I try to write it out & hope someone can point out my mistake...
Thank you very much
Here's my code:
#include <Servo.h>
Servo myservo1;Â // create servo object to control a servo
Servo myservo2;
int pos = 0;Â Â // variable to store the servo position
volatile long transmitterValue; // to store the transmitter position/value
void setup()
{Â
 myservo1.attach(10);Â
 myservo2.attach(11);
 attachInterrupt(0, servoPosition, CHANGE); //interrupt function to control the servo position when receive signal
 Serial.begin(57600); // to link the board & send the data to computer
 Serial.println("Done with setup");
}
void checkTransmitter()
{
 transmitterValue = ( pulseIn(2, HIGH, 100000) / 10 ); // Read RC channel from the interrupt pin
}
void servoPosition ()Â // interrupt function
{
 if ( transmitterValue < 130 )
 {
  myservo2.write(30);
 }Â
Â
 else if ( transmitterValue > 150 )
 {
  myservo2.write(150);
 }
 else
 {
  myservo2.write(90);
 }
}
void sweepingServo()
{
  for(pos > 30; pos < 150; pos += 1)Â
  {                Â
   myservo1.write(pos);     Â
   delay(20);  Â
  }
 Â
  for(pos < 150; pos > 30; pos -= 1) Â
  {               Â
   myservo1.write(pos);      Â
   delay(20); Â
  }
}
void loop ()
{
 checkTransmitter();
 sweepingServo();
 servoPosition ();
 Serial.print("data:");
 Serial.println(transmitterValue);
 delay(200);
}