' This program ramps a DC Motor's speed up and down ' and forwards and backwards, using the L298 H-Bridge ' on the OOBOT43-1 Controller Board. ' waits for SW1 press, then runs motor sequence 4 times. Dim A As New oDCMotor2 ' motor A connected M1-to-M2 Dim B As New oDCMotor2 ' motor B connected M3-to-M4 Dim x as Byte Dim sw1 as New oDio1 ' switch SW1 on RC0 (also Led L2) Dim Frq As New oFreq ' tone output on pin RC5 Sub Main() A.IOLineP = 18 ' PWM1 A.IOLine1 = 24 ' RD0 A.IOLine2 = 25 ' RD1 A.Operate = 1 A.Prescale = 1 A.Brake = cvOff B.IOLineP = 17 ' PWM2 B.IOLine1 = 26 ' RD2 B.IOLine2 = 27 ' RD3 B.Operate = 1 B.Brake = cvOff sw1.ioline = 16 ' RC0 sw1.direction = cvinput Do if sw1=0 then sw1.direction = cvoutput sw1 = 0 call motrun call motrun call motrun call motrun end if sw1.direction = cvinput oopic.delay = 2 Loop End Sub sub motrun() ' ramp velocity up+down in one direction. For x = 40 To 126 A = x B = x OOPic.Delay = 20 Next x OOpic.delay = 100 For x = 0 to 40 A = 126 - x B = 126 - x OOPic.Delay = 20 Next x call play1 ' ramp velocity up+down in other direction. For x = 0 To 126 A = -1*x B = -1*x OOPic.Delay = 5 Next x OOpic.delay = 100 For x = 0 to 126 A = -1*(126 - x) B = -1*(126 - x) OOPic.Delay = 5 Next x end sub ' play a short tune on the piezo on RC5 Sub Play1() Frq.Beep(64000,10) Frq.Beep(64500,10) Frq.Beep(65000,10) Frq.Beep(63500,5) Frq.Beep(63600,5) Frq.Beep(0,10) Frq.Beep(5500,10) Frq.Beep(0,10) Frq.Beep(5500,10) Frq.Beep(0,10) End Sub