Könnyen betanítható a mozgásra, amelyet azután egyszer, vagy végtelenszer ismétel. A betanult programot fájlba el lehet menteni, illetve a programot tartalmazó fájlt be lehet tölteni. A cél az volt, hogy minél kevesebb pénzbe kerüljön, és ez felülírt mindent. Ettől függetlenül elég jó játék :) !
Hozzávalók:
Arduino nano:
https://www.hestore.hu/prod_10035527.html
4 db. mikrószervo motor: 9g SG90:
https://www.hestore.hu/prod_10031188.html
1db próbapanel, pl.:
https://www.hestore.hu/prod_10024298.html
Vezetékek...
Max. ár 6000 HUF
Ha az Ebay-ről rendeled a hozzávalókat, akkor sokkal olcsóbb!
Robot arm (Robotkar) 2.
https://drive.google.com/file/d/17vZVXRSODmgt3l84ecP-ILOMlRudRkfm/view?usp=sharing
This VB project download here:
https://drive.google.com/open?id=1XBbGaiigkBsGEXXy4TKp7OwKkwhXemvM
( You need creat a robot.txt file here: C:\robot )
VB code (kód):
Imports System
Imports System.IO.Ports
Public Class Form1
Dim comPORT As String
Dim receivedData As String = ""
Dim bejovo As String
Dim kimeno As Integer
Dim array(0 To 1000) As Integer
Dim array2(0 To 4) As Integer
Dim n As Integer
Dim n2 As Integer
Dim n3 As Integer = 0
Dim n4 As Integer
Dim k As Integer
Dim szoveg As String
Dim elozo As Integer
Dim repeat As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = False
comPORT = ""
For Each sp As String In My.Computer.Ports.SerialPortNames
ComboBox1.Items.Add(sp)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If (ComboBox1.SelectedItem <> "") Then
comPORT = ComboBox1.SelectedItem
End If
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
If (Button5.Text = "Start") Then
If (comPORT <> "") Then
SerialPort1.Close()
SerialPort1.PortName = comPORT
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default 'very important!
SerialPort1.ReadTimeout = 10000
SerialPort1.Open()
Button5.Text = "Stop"
ComboBox1.Enabled = False
Button12.Enabled = True
Else
MsgBox("Select a COM port first")
End If
Else
SerialPort1.Close()
Button5.Text = "Start"
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button6.Enabled = False
Button7.Enabled = False
Button8.Enabled = False
Button9.Enabled = False
Button10.Enabled = False
Button11.Enabled = False
Button12.Enabled = False
Button13.Enabled = False
Button14.Enabled = False
Button15.Enabled = False
Button16.Enabled = False
Button17.Enabled = False
Button18.Enabled = False
Button19.Enabled = False
Button20.Enabled = False
Button21.Enabled = False
Button22.Enabled = False
Button23.Enabled = False
Timer1.Stop()
ComboBox1.Enabled = True
ComboBox1.Text = String.Empty
Label9.Text = "Push it! -->"
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
receivedData = ReceiveSerialData()
If ((receivedData.Contains("<") And receivedData.Contains(">"))) Then
parseData()
End If
Timer1.Enabled = True
End Sub
Function ReceiveSerialData() As String
Dim Incoming As String
Try
Incoming = SerialPort1.ReadExisting()
If Incoming Is Nothing Then
Return "nothing" & vbCrLf
Else
Return Incoming
End If
Catch ex As TimeoutException
Return "Error: Serial Port read timed out."
End Try
End Function
Function parseData()
Dim pos1 As Integer
Dim pos2 As Integer
Dim length As Integer
Dim newCommand As String
Dim done As Boolean = False
While (Not done)
pos1 = receivedData.IndexOf("<") + 1
pos2 = receivedData.IndexOf(">") + 1
If (pos2 < pos1) Then
receivedData = Microsoft.VisualBasic.Mid(receivedData, pos2 + 1)
pos1 = receivedData.IndexOf("<") + 1
pos2 = receivedData.IndexOf(">") + 1
End If
If (pos1 = 0 Or pos2 = 0) Then
done = True
Else
length = pos2 - pos1 + 1
If (length > 0) Then
newCommand = Mid(receivedData, pos1 + 1, length - 2)
receivedData = Mid(receivedData, pos2 + 1)
If (newCommand.Substring(0, 1) = "A") Then
Label1.Text = newCommand.Substring(1, 4)
End If
End If
End If
End While
End Function
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
SerialPort1.Write("9")
Label8.Text = 1
Button1.Text = "Left"
Button2.Text = "Right"
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
array(n) = Label1.Text
n = n + 1
Label4.Text = n
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
elozo = 0
SerialPort1.Write(array(0))
n2 = 1
n4 = 0
Label4.Text = Label4.Text - 1
Threading.Thread.Sleep(1000)
Timer2.Start()
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
If (n2 <> n And Label1.Text <> elozo) Then
Label6.Text = array(n2)
SerialPort1.Write(array(n2))
n2 = n2 + 1
Label4.Text = Label4.Text - 1
End If
If (n2 >= n) Then
If (n4 = 0) Then
Timer2.Stop()
Label4.Text = 0
End If
If (n4 = 1) Then
n2 = 0
End If
End If
elozo = Label1.Text
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
ReDim array(0 To 1000)
n = 0
n2 = 0
n4 = 0
Label4.Text = n
End Sub
Private Sub Button1_MouseDown(sender As Object, e As MouseEventArgs) Handles Button1.MouseDown
SerialPort1.Write("2397")
Label1.Text = 2397
End Sub
Private Sub Button1_MouseUp(sender As Object, e As MouseEventArgs) Handles Button1.MouseUp
SerialPort1.Write("2")
End Sub
Private Sub Button2_MouseDown(sender As Object, e As MouseEventArgs) Handles Button2.MouseDown
SerialPort1.Write("643")
Label1.Text = 643
End Sub
Private Sub Button2_MouseUp(sender As Object, e As MouseEventArgs) Handles Button2.MouseUp
SerialPort1.Write("2")
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
SerialPort1.Write("8")
Label8.Text = 2
Button1.Text = "Down"
Button2.Text = "Up"
End Sub
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
n3 = 0
array2(0) = 9
array2(1) = 8
array2(2) = 7
array2(3) = 6
Timer3.Start()
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
SerialPort1.Write("7")
Label8.Text = 3
Button1.Text = "Up"
Button2.Text = "Down"
End Sub
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
SerialPort1.Write("6")
Label8.Text = 4
Button1.Text = "Grip"
Button2.Text = "Let off"
End Sub
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
If (n3 < 4) Then
SerialPort1.Write(array2(n3))
End If
n3 = n3 + 1
If (n3 = 4) Then
Timer3.Stop()
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
Button6.Enabled = True
Button7.Enabled = True
Button8.Enabled = True
Button9.Enabled = True
Button10.Enabled = True
Button11.Enabled = True
Button13.Enabled = True
Button14.Enabled = True
Button15.Enabled = True
Button16.Enabled = True
Button17.Enabled = True
Button18.Enabled = True
Button19.Enabled = True
Button20.Enabled = True
Button21.Enabled = True
Button22.Enabled = True
Button23.Enabled = True
Timer1.Start()
Label9.Text = "Robot are working!"
End If
End Sub
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
n2 = 0
Timer4.Start()
End Sub
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
SerialPort1.Write("1300")
Label8.Text = 1300
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
SerialPort1.Write("1100")
Label8.Text = 1100
End Sub
Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
SerialPort1.Write("1300")
Label8.Text = 1300
End Sub
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
SerialPort1.Write("800")
Label8.Text = 800
End Sub
Private Sub Timer4_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
If (n2 <> n) Then
Label10.Text = array(n2)
My.Computer.FileSystem.WriteAllText("c:\robot\robot.txt", CStr(Label10.Text) + "+", True)
n2 = n2 + 1
End If
If (n2 >= n) Then
Timer4.Stop()
End If
End Sub
Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
n = 0
Timer5.Start()
End Sub
Private Sub Timer5_Tick(sender As Object, e As EventArgs) Handles Timer5.Tick
szoveg = My.Computer.FileSystem.ReadAllText("c:\robot/robot.txt")
szoveg = Val(szoveg.Split("+")(n))
Label10.Text = szoveg
array(n) = szoveg
k = Convert.ToInt32(szoveg)
If (k > 0) Then
n = n + 1
End If
If (k = 0) Then
Timer5.Stop()
End If
End Sub
Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click
End Sub
Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click
elozo = 0
SerialPort1.Write(array(0))
n2 = 1
n4 = 1
Label4.Text = Label4.Text - 1
Threading.Thread.Sleep(1000)
Timer2.Start()
End Sub
Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click
n4 = 0
End Sub
Private Sub Button21_Click(sender As Object, e As EventArgs) Handles Button21.Click
If (TextBox1.Text > 642 And TextBox1.Text < 2398) Then
SerialPort1.Write(TextBox1.Text)
End If
End Sub
Private Sub Button22_Click(sender As Object, e As EventArgs) Handles Button22.Click
SerialPort1.Write(10)
End Sub
Private Sub Button23_Click(sender As Object, e As EventArgs) Handles Button23.Click
SerialPort1.Write(5)
End Sub
End Class
----------------------------------------------
Arduino kód:
#include <Servo.h>
Servo myservo;
int bejovo;
int pozi;
int pozi6 = 800;
int pozi7 = 1300;
int pozi8 = 1100;
int pozi9 = 1300;
int motor;
int elozo;
int elozo2;
int gyors = 10;
const boolean DEBUG = true;
unsigned int kimeno;
char karakterhossz[10];
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available()){
bejovo = Serial.parseInt();
}
if( bejovo != elozo){
if (bejovo == 6){
motor = 6;
formatNumber( 6, 4);
Serial.print("<A");
Serial.print(karakterhossz);
Serial.print(">");
if (DEBUG) { Serial.println(""); }
}
if (bejovo == 7){
motor = 7;
formatNumber( 7, 4);
Serial.print("<A");
Serial.print(karakterhossz);
Serial.print(">");
if (DEBUG) { Serial.println(""); }
}
if (bejovo == 8){
motor = 8;
formatNumber( 8, 4);
Serial.print("<A");
Serial.print(karakterhossz);
Serial.print(">");
if (DEBUG) { Serial.println(""); }
}
if (bejovo == 9){
motor = 9;
formatNumber( 9, 4);
Serial.print("<A");
Serial.print(karakterhossz);
Serial.print(">");
if (DEBUG) { Serial.println(""); }
}
if (motor == 9){
pozi = pozi9;
}
if (motor == 8){
pozi = pozi8;
}
if (motor == 7){
pozi = pozi7;
}
if (motor == 6){
pozi = pozi6;
}
if (bejovo == 2){
bejovo = pozi;
kimeno = pozi;
formatNumber( kimeno, 4);
Serial.print("<A");
Serial.print(karakterhossz);
Serial.print(">");
if (DEBUG) { Serial.println(""); }
}
}
if(bejovo > 642 && bejovo < 2398){
if( pozi < bejovo){
pozi = pozi + 1;
}
if( pozi > bejovo){
pozi = pozi - 1;
}
}
myservo.attach(motor,640,2400);
myservo.write(pozi);
if (motor == 9){
pozi9 = pozi;
}
if (motor == 8){
pozi8 = pozi;
}
if (motor == 7){
pozi7 = pozi;
}
if (motor == 6){
pozi6 = pozi;
}
if (bejovo == pozi){
if (pozi != elozo2){
kimeno = pozi;
formatNumber( kimeno, 4);
Serial.print("<A");
Serial.print(karakterhossz);
Serial.print(">");
if (DEBUG) { Serial.println(""); }
}
}
elozo = bejovo;
elozo2 = pozi;
if (bejovo == 5){
gyors = 5;
}
if (bejovo == 10){
gyors = 10;
}
delay(gyors);
}
void formatNumber( unsigned int number, byte digits)
{
char kimenoString[10] = "\0";
strcpy(karakterhossz, kimenoString);
itoa (number, kimenoString, 10);
byte numZeros = digits - strlen(kimenoString) ;
if (numZeros > 0)
{
for (int i=1; i <= numZeros; i++) { strcat(karakterhossz,"0"); }
}
strcat(karakterhossz,kimenoString);
}
Robotkar 1:
Ezeken kívül néhány kerékpár küllő, és néhány kartonplaszt darabból épül fel., meg egy kevés cérnát is használtam. A kartonplaszt olyan mint a karton, csak műanyagból van. Lehet kartonból is csinálni, csak akkor még igénytelenebbül fog kinézni, de ugyanúgy fog működni...Az egészet egy ragasztópisztollyal ragasztottam össze, egy asztali lámpa alja részére, ami a kar alapját képezi. Gyors, egyszerű dolog...
Nem igényes de tapasztalatszerzésre, és tanulás céljára jó volt, és jó játszani vele, na meg persze, ha van rá idő, kedv, szebb, vagy más koncepciójú kivitelbe is megépíthető, a youtube-on találunk rá példákat. A motorokat egymás után használom a programban, mindig csak egy van bekapcsolva, így elméletileg nem kell külön tápellátás, lehet használni az arduino 5 V-ját is. Azonban ekkor, amikor rácsatlakozunk a portra, vagy/és a tápra, vagy le, akkor hirtelen kaphatnak a szervok egy rövid jelet, amire egyszerre aktivizálhatják egy pillanatra magukat, és akkor arra a pillanatra nagy lehet az áramfelvétel. Ezért ha nem külső tápról, pl 4,5V-os elemről megy, hanem az arduino 5V-jától kapja a delejt, akkor a program csatlakoztatását követően, sorban egymás után kapcsoljuk be a motorokat, hogy ezt is elkerüljük.Ugyanígy a kikapcsolás előtt, vegyük le egymás után a motorokat a tápról. Ha nem az aduino tápját akarjuk használni, hanem elemről, vagy adapterről hajtjuk meg a motorokat, akkor viszont nem kell ezzel szórakozni.
A monitorról, egérrel lehet vezérelni, így néz ki a monitoron a Visual Basicben megírt vezérlése.
Ez az első működése, és annyira tetszett, hogy azonnal felvettem. Aztán egy kicsit igényesebbre csináltam, de ez a felvétel elég rossz minőségű, mert nem volt rendes kamerám, este is volt, a fényviszonyok is rosszak voltak...
(Frissítés:Egyszerűbb, szebb, teljesen más felépítésű robotkart használok, a videó hamarosan, pár nap, most sajnos kameragondjaim vannak..)
tartalmaz 1 SerialPortot, és 6 db. Timer-t. A startgomb kivételével a gombok alapban enabled false-ra vannak állítva. Létre kell hozni a c meghajtón egy robot nevű mappát. Ebbe létrehoz egy robot nevű txt file-t, amelybe vagy ahonnan a robot mozgásának a programja elmenthető, vagy betölthető:
https://drive.google.com/open?id=197kglARDmqkbzbvuT0fITGGLnJZcrVaP
Modul:
Imports System
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
Dim path As String = "c:\robot\robot.txt"
Dim fs As FileStream = File.Create(path)
End Sub
End Module
És a form1 kódja:
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Dim comPORT As String
Dim receivedData As Char = ""
Dim motor As Integer
Dim motor2 As Integer
Dim array(0 To 1000) As Integer
Dim n As Integer
Dim k As Integer
Dim i As Integer
Dim repeat As Integer
Dim plsp As Integer
Dim szoveg As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
n = 0
k = 0
i = 0
repeat = 0
plsp = 0
Label1.Text = 90
Label2.Text = 90
Label3.Text = 50
Label9.Text = 50
Label10.Text = 45
comPORT = ""
For Each sp As String In My.Computer.Ports.SerialPortNames
ComboBox1.Items.Add(sp)
Next
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If (ComboBox1.SelectedItem <> "") Then
comPORT = ComboBox1.SelectedItem
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (Button1.Text = "Start") Then
If (comPORT <> "") Then
SerialPort1.Close()
SerialPort1.PortName = comPORT
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default 'very important!
SerialPort1.ReadTimeout = 10000
SerialPort1.Open()
Button1.Text = "Stop"
ComboBox1.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
Button9.Enabled = True
Button12.Enabled = True
Button18.Enabled = True
Button19.Enabled = True
Button15.Enabled = True
Button16.Enabled = True
Button2.Enabled = True
Button5.Enabled = True
Button8.Enabled = True
Button11.Enabled = True
Button17.Enabled = True
Button10.Enabled = True
Button20.Enabled = True
Button21.Enabled = True
Else
MsgBox("Select a COM port first")
End If
Else
SerialPort1.Close()
Button1.Text = "Start"
ComboBox1.Enabled = True
ComboBox1.Text = String.Empty
Button3.Enabled = False
Button4.Enabled = False
Button9.Enabled = False
Button12.Enabled = False
Button18.Enabled = False
Button19.Enabled = False
Button15.Enabled = False
Button16.Enabled = False
Button2.Enabled = False
Button5.Enabled = False
Button8.Enabled = False
Button11.Enabled = False
Button17.Enabled = False
Button10.Enabled = False
Button20.Enabled = False
Button21.Enabled = False
End If
End Sub
Function ReceiveSerialData() As String
Dim Incoming As String
Try
Incoming = SerialPort1.ReadExisting()
If Incoming Is Nothing Then
Return "nothing" & vbCrLf
Else
Return Incoming
End If
Catch ex As TimeoutException
Return "Error: Serial Port read timed out."
End Try
End Function
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
Private Sub Button2_MouseDown(sender As Object, e As MouseEventArgs) Handles Button2.MouseDown
Label1.Text = Label2.Text
motor = 91
motor2 = 95
Timer2.Start()
End Sub
Private Sub Button2_MouseUp(sender As Object, e As MouseEventArgs) Handles Button2.MouseUp
Label2.Text = Label1.Text
Timer2.Stop()
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
If Label1.Text < 180 Then
SerialPort1.Write(Chr(motor))
Label1.Text = Label1.Text + 2
If plsp = 1 And n < 1000 Then
array(n) = motor
n = n + 1
k = k + 1
Label4.Text = n
End If
If n = 1000 Then
n = 0
End If
End If
End Sub
Private Sub Button3_MouseDown(sender As Object, e As MouseEventArgs) Handles Button3.MouseDown
Label1.Text = Label2.Text
motor = 92
motor2 = 95
Timer1.Start()
End Sub
Private Sub Button3_MouseUp(sender As Object, e As MouseEventArgs) Handles Button3.MouseUp
Label2.Text = Label1.Text
Timer1.Stop()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
End Sub
Private Sub Button4_MouseDown(sender As Object, e As MouseEventArgs) Handles Button4.MouseDown
Label1.Text = Label3.Text
Timer2.Start()
motor = 93
motor2 = 96
End Sub
Private Sub Button4_MouseUp(sender As Object, e As MouseEventArgs) Handles Button4.MouseUp
Label3.Text = Label1.Text
Timer2.Stop()
End Sub
Private Sub Button5_MouseDown(sender As Object, e As MouseEventArgs) Handles Button5.MouseDown
Label1.Text = Label3.Text
motor = 94
motor2 = 96
Timer1.Start()
End Sub
Private Sub Button5_MouseUp(sender As Object, e As MouseEventArgs) Handles Button5.MouseUp
Label3.Text = Label1.Text
Timer1.Stop()
End Sub
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
If n < k Then
SerialPort1.Write(Chr(array(n)))
Label5.Text = array(n)
n = n + 1
Label4.Text = n
End If
If n = k Then
Label4.Text = 0
If repeat = 0 Then
Timer3.Stop()
End If
If repeat = 1 Then
n = 0
End If
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Label1.Text > 2 Then
SerialPort1.Write(Chr(motor))
Label1.Text = Label1.Text - 2
If plsp = 1 And n < 1000 Then
array(n) = motor
n = n + 1
k = k + 1
Label4.Text = n
End If
If n = 1000 Then
n = 0
End If
End If
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
End Sub
Private Sub Button9_MouseDown(sender As Object, e As MouseEventArgs) Handles Button9.MouseDown
Label1.Text = Label9.Text
motor = 97
motor2 = 99
Timer2.Start()
End Sub
Private Sub Button9_MouseUp(sender As Object, e As MouseEventArgs) Handles Button9.MouseUp
Label9.Text = Label1.Text
Timer2.Stop()
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
End Sub
Private Sub Button8_MouseDown(sender As Object, e As MouseEventArgs) Handles Button8.MouseDown
Label1.Text = Label9.Text
motor = 98
motor2 = 99
Timer1.Start()
End Sub
Private Sub Button8_MouseUp(sender As Object, e As MouseEventArgs) Handles Button8.MouseUp
Label9.Text = Label1.Text
Timer1.Stop()
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
End Sub
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
Label10.Text = 170
Label1.Text = Label10.Text
motor2 = 100
SerialPort1.Write(Chr(100))
If plsp = 1 And n < 1000 Then
array(n) = 100
n = n + 1
k = k + 1
Label4.Text = n
End If
End Sub
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
Label10.Text = 45
Label1.Text = Label10.Text
motor2 = 101
SerialPort1.Write(Chr(101))
If plsp = 1 And n < 1000 Then
array(n) = 101
n = n + 1
k = k + 1
Label4.Text = n
End If
End Sub
Private Sub Label6_Click(sender As Object, e As EventArgs) Handles Label6.Click
End Sub
Private Sub Button13_Click(sender As Object, e As EventArgs)
Timer3.Stop()
Timer4.Stop()
repeat = 0
n = 0
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
Timer3.Stop()
repeat = 0
n = 0
k = 0
ReDim array(0 To 1000)
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
Timer3.Stop()
Timer4.Stop()
repeat = 0
n = 0
SerialPort1.Write(Chr(45))
Threading.Thread.Sleep(1000)
SerialPort1.Write(Chr(102))
Label1.Text = 90
Label2.Text = 90
Label3.Text = 50
Label9.Text = 50
End Sub
Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
plsp = 1
End Sub
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
plsp = 0
End Sub
Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
n = 0
repeat = 0
Timer4.Start()
End Sub
Private Sub Timer4_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
If n < k Then
SerialPort1.Write(Chr(array(n)))
Label5.Text = array(n)
n = n + 1
Label4.Text = n
End If
If n = k Then
Label4.Text = 0
If repeat = 0 Then
Timer4.Stop()
End If
If repeat = 1 Then
n = 0
End If
End If
End Sub
Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click
n = 0
repeat = 1
Timer4.Start()
End Sub
Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click
n = 0
repeat = 0
Timer5.Start()
End Sub
Private Sub Timer5_Tick(sender As Object, e As EventArgs) Handles Timer5.Tick
If n < k Then
My.Computer.FileSystem.WriteAllText("c:\robot\robot.txt", Chr(array(n)), True)
Label5.Text = array(n)
n = n + 1
Label4.Text = n
End If
If n = k Then
Label4.Text = 0
If repeat = 0 Then
Timer5.Stop()
End If
If repeat = 1 Then
n = 0
End If
End If
End Sub
Private Sub Button21_Click(sender As Object, e As EventArgs) Handles Button21.Click
Timer3.Stop()
repeat = 0
szoveg = My.Computer.FileSystem.ReadAllText("c:\robot\robot.txt")
k = szoveg.Length()
n = 0
Timer6.Start()
End Sub
Private Sub Timer6_Tick(sender As Object, e As EventArgs) Handles Timer6.Tick
If n < k Then
szoveg = String.Join("-", szoveg)
array(n) = Convert.ToInt32(szoveg(n))
Label4.Text = n
n = n + 1
End If
If n = k Then
Label4.Text = 0
If repeat = 0 Then
Timer6.Stop()
End If
End If
End Sub
End Class
Arduino kód:
#include <Servo.h>
Servo myservo;
int degree;
int degree1 = 90;
int degree2 = 50;
int degree3 = 50;
int szam = 0;
void setup(){
Serial.begin(9600);
}
void loop() {
if (Serial.available()>0){
char val = Serial.read();
szam = int(val);
if(szam == 91 && degree1 < 180){
degree1 = degree1 + 2;
myservo.attach(9);
myservo.write(degree1);
}
if(szam == 92 && degree1 > 0){
degree1 = degree1 - 2;
myservo.attach(9);
myservo.write(degree1);
}
if(szam == 93 && degree2 < 180){
degree2 = degree2 + 2;
myservo.attach(8);
myservo.write(degree2);
}
if(szam == 94 && degree2 > 0){
degree2 = degree2 - 2;
myservo.attach(8);
myservo.write(degree2);
}
if(szam == 97 && degree3 < 180){
degree3 = degree3 + 2;
myservo.attach(7);
myservo.write(degree3);
}
if(szam == 98 && degree3 > 0){
degree3 = degree3 - 2;
myservo.attach(7);
myservo.write(degree3);
}
if(szam < 90){
degree = szam * 2;
}
if(szam == 95){
myservo.attach(9);
myservo.write(degree);
}
if(szam == 96){
myservo.attach(8);
myservo.write(degree);
}
if(szam == 99){
myservo.attach(7);
myservo.write(degree);
}
if(szam == 100){
myservo.attach(6);
myservo.write(170);
}
if(szam == 101){
myservo.attach(6);
myservo.write(45);
}
if(szam == 102){
myservo.attach(6);
myservo.write(45);
delay(1000);
myservo.attach(9);
myservo.write(90);
degree1 = 90;
delay(1000);
myservo.attach(8);
myservo.write(50);
degree2 = 50;
delay(1000);
myservo.attach(7);
myservo.write(50);
degree3 = 50;
}
}
delay(20);
}