okey so im using this code that were posted on this site. i also link my electronic schematic so someone can check if thats correct.
my problem is that the servo is only turning into one direction. hope someone can help me to fix this.
// Designed for Skull Quadcopter
// Rev 1.0
#include <Servo.h>
#include <PinChangeInt.h>
// Define RX variables
#define PIN1 2
#define PIN1dataReg PIND
#define pin1state (PIN1dataReg & (1 << PIN1))
volatile long pulseStart1; // pulse start time measured from millies in ISR for pin 1
volatile long pulseTime1; // pulse width time measured from millies in ISR for pin 1 <-- this is the output we require
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
// Define Microswitch pins
const int msdown = 5;
const int msup = 4;
int msdownstate = 0;
int msupstate = 0;
// Define Variables for LEDs
int led1 = 6; // output pin for LED 1
int led2 = 7; // output pin for LED 2
int led3 = 8; // output pin for LED 3
int led4 = 9; // output pin for LED 4
int led13 = 13; // onboard LED indictor incase no others are attached
unsigned long time; // holds current time for change of state
int flashtime = 400; // time to flash LEDs in milliseconds
boolean ledon = false; // remembers start of LED
boolean movedown = true; // safety feature
boolean moveup = true; // safety feature
// The below procedure handles the pulse from the RX input
void handlePin1()
{
if(pin1state)
pulseStart1=micros(); // we got a positive edge
else
pulseTime1=micros()-pulseStart1; // Negative edge: get pulsewidth
}
// LED Control - very basic, can be expanded.
void turnledoff() {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led13, LOW);
}
void turnledon() {
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led13, HIGH);
}
void flashled() {
// LED Flash
if (millis() - time > flashtime){
time = millis();
if (ledon){
turnledoff();
ledon = false;
} else {
turnledon();
ledon = true;
}
}
}