B4R Question Servo motor 90 degrees?

Beja

Expert
Licensed User
Longtime User
Hello all,
After trying many times I utterly failed to return the servo motor from 90 degrees. It just stopped and didn't move. I was editing the Servo example by Erel, and replaced the 180 angel degrees to 90. what wrong am doing?
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public servo1 As Servo
    Public pinservo As Pin
    Public Timer1 As Timer
    Public angleservo As UInt
    Public upangle As Boolean

End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    pinservo.Initialize (4,pinservo.MODE_OUTPUT)    'connect servo to pin 4 of Arduino
    servo1.Attach(pinservo.PinNumber)                'assign servo to device on pin servo

    Timer1.Initialize ("Timer1_Tick",100)            'Call Timer every second
    Timer1.Enabled=True

    angleservo=servo1.Read                             'initial servo angle
    upangle=True                                    'Increment angle

End Sub

Sub Timer1_Tick

    angleservo=servo1.read
   
    Select upangle                                    'Increment angle
   
        Case True
            If (angleservo >=0 And angleservo <180) Then
                Log ("up angle ",angleservo)
                angleservo=angleservo +1
                servo1.Write(angleservo)
            End If
       
            If angleservo=180 Then upangle=False
       
        Case False                                    'Decrement angle
       
            If angleservo <=180 And angleservo>0 Then
                Log ("down angle ",angleservo)
                angleservo=angleservo-1
                servo1.Write(angleservo)
            End If
       
            If angleservo=0 Then upangle=True
   
    End Select

End Sub
 

Beja

Expert
Licensed User
Longtime User
Tutorial... https://www.b4x.com/android/forum/threads/servo-motor-and-arduino.66051/

The code there seems identical to yours.

I'm no expert, but I understand there are servos that are non-standard & modified, as well as plain standard ones. You need the right type.
https://www.b4x.com/android/forum/threads/servo-motor-360-degrees.103116/

Thanks Mike..
Those were discussing a different thing.. But still no info aboutput how to stop at or return from 90 degrees ..
 
Upvote 0
Top