hey everyone, so i making this project and i don't know how to stop motor dc after 7 seconds i mean i want it to work in certain time but it keeps spinning and when i upload it , it is keep spinning
what i'd like to make : when i upload it the motor doesnt spin and when i hit 1st button on vb the motor will spin in 7 seconds and when i hit 2nd button the motor will shut and i don't know how to program it , please help me ![]()
here is my arduino source code:
#define in1 2
#define in2 1
void setup()
{
pinMode(in1, OUTPUT);
pinMode(in2,OUTPUT);
Serial.begin(9600);
}
void loop()
{
while (Serial.available() == 0);
int val = Serial.read() - '0';
if (val == 1) {
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
}
else if (val == 2)
{
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
}
else
{
//val = val;
}
Serial.println(val);
Serial.flush(); // clear serial port
}
and my visual basic code:
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Open()
SerialPort1.Write("1")
SerialPort1.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "com8"
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPort1.Open()
SerialPort1.Write("2")
SerialPort1.Close()
End Sub
End Class