servo.bas

来自「Bascom 8051 servo motor control」· BAS 代码 · 共 26 行

BAS
26
字号
'----------------------------------------------------------------------
'                      (c) 2000 MCS Electronics
'                    examples that shows how to use Servos
'----------------------------------------------------------------------
'First we tell the compiler how much servos we want to use
'and to which pins they are connected
Config Servos = 2 , Servo1 = P3.5 , Servo2 = P3.7 , Reload = 100
'The maximum mnumber of servos to use is 16
'The RELOAD value is the step value. In this example 100 uS is used
'You could use a lower value for a more precise stepping

'Now we want to control the pulse duration
'A normal servo has a range from 800-1600 uS and 1200 is the middle
'Each value is 100 uS so for 800 we specify 8
Dim Key As Byte
Servo1 = 8                                                    'to the left
Servo2 = 16                                                   'to the right
Do
  Print "*"
  Wait 1                                                      'this will take some longer because of the interrupt used
  Key = Inkey()
  If Key = 49 Then                                            'if we press 1
     Servo1 = 12                                              '1200 uS
  End If
Loop
End

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?