Ozirock's Projects

"A person who never made a mistake never tried anything new" - Albert Einstein

Preset Path

Members Area

 

 

 

Useful Tools

 

 

Recent Videos

2755 views - 0 comments
2289 views - 0 comments
2222 views - 0 comments

Newest Members

 

 

 

Preset path using a timer

I modified the code of the car to make it follow a set path, turning after certain iterations of time. Below you'll find a picture of the form and also the code.

  

VB Code: 

Public Class Form1

Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer
Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Public time

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim CardAddress As Integer
Dim h As Integer
CardAddress = 3

h = OpenDevice(3)
Label1.Text = "Card " + Str(h) + " connected"

End Sub
Private Sub MainForm_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

Select Case e.KeyCode
Case Keys.A : SetDigitalChannel(1) : Label5.ForeColor = Color.Red
Case Keys.L : SetDigitalChannel(2) : Label4.ForeColor = Color.Red
Case Keys.Z : SetDigitalChannel(3) : Label2.ForeColor = Color.Red
Case Keys.K : SetDigitalChannel(4) : Label3.ForeColor = Color.Red
End Select

End Sub

Private Sub MainForm_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp

Select Case e.KeyCode
Case Keys.A : ClearDigitalChannel(1) : Label5.ForeColor = Color.Black
Case Keys.L : ClearDigitalChannel(2) : Label4.ForeColor = Color.Black
Case Keys.Z : ClearDigitalChannel(3) : Label2.ForeColor = Color.Black
Case Keys.K : ClearDigitalChannel(4) : Label3.ForeColor = Color.Black
End Select

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

time = time + 1

If time = 5 Then : SetDigitalChannel(1) : Label5.ForeColor = Color.Red

End If

If time = 10 Then : SetDigitalChannel(2) : Label4.ForeColor = Color.Red

End If

If time = 15 Then : ClearDigitalChannel(2) : Label4.ForeColor = Color.Black

End If

If time = 20 Then : ClearDigitalChannel(1) : Label5.ForeColor = Color.Black : SetDigitalChannel(3) : Label2.ForeColor = Color.Red

End If

If time = 30 Then : SetDigitalChannel(2) : Label4.ForeColor = Color.Red

End If

If time = 35 Then : ClearDigitalChannel(2) : Label4.ForeColor = Color.Black

End If

If time = 40 Then : ClearDigitalChannel(3) : Label2.ForeColor = Color.Black

End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = True
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Timer1.Enabled = False
time = 0
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
time = 0
End Sub
End Class

 Here's a quick video of the car in action: