I have tried, through my WHOLE SUNDAY to get this code:
DO
IF PULSES < 600 THEN
GOTO increment
ELSEIF PULSES > 1150 THEN
GOTO decrement
ENDIF
increment:
PULSES = 600
DO
PULSES = PULSES + 25
PULSOUT 15, PULSES
PAUSE 20
LOOP UNTIL PULSES > 1150
RETURN
decrement:
PULSES = 1150
DO
PULSES = PULSES - 25
PULSOUT 15, PULSES
PAUSE 20
LOOP UNTIL PULSES < 600
RETURN
LOOP
...And trun it into Arduino code. So far, I have been unsuccessful, and I already blew out a nice Hitec micro servo in the process. Does anyone in these forums have experience with PBASIC code? I need to get the arduino code to do what the PBASIC code is written to do. If not, I can explain how the PBASIC code works. By now though, I am pretty frustrated with my servo program. Can anyone help me??!! ![]()
Here's my (unsuccessful) Arduino code (ignore the commented out parts):
int servoPin = 3;
int irPin = 0;
int val = 0;
int pulses;
void setup() {
Serial.begin(9600);
pinMode(servoPin, OUTPUT);
}
void loop()
{
if(pulses < 1250)
increment();
else if(pulses > 2225)
decrement();
//val = analogRead(irPin);
//delay(5);
//Serial.println("PULSE");
//Serial.println(pulses);
//delay(5);
//Serial.println("IR");
//delay(5);
//Serial.println(val);
}
void increment()
{
//pulses = 1250;
while(pulses > 1252)
{
pulses = pulses + 15;
digitalWrite(servoPin, HIGH);
delay(pulses);
digitalWrite(servoPin, LOW);
delay(20);
}
return;
}
void decrement()
{
//pulses = 2225;
while(pulses > 1252)
{
pulses = pulses - 15;
digitalWrite(servoPin, HIGH);
delay(pulses);
digitalWrite(servoPin, LOW);
delay(20);
}
return;
}