Go Down

Topic: diabling one of stepper motor in arduino with vb2010 (Read 274 times) previous topic - next topic

wentaw

hi guys,

what code do i have to insert to disable one of the stepper motor here?

like, i want to run 'myStepper' alone and disable 'myStepper1'. i have 2 stepper motors and  choose 1 to run first (either 1 or 0 using button in vb2010) , and then i assign how many revolution the selected motor is going to have (using textbox).

once i click button '0' in vb, one of the stepper will disable. is it possible?


Code: [Select]

#include <Stepper.h>
#define stepsPerRevolution 900
#define stepsPerRevolution1 900
Stepper myStepper(stepsPerRevolution,  4, 5, 6, 7);
Stepper myStepper1(stepsPerRevolution1, 8, 9, 10, 11);
int mot;


void setup()
{

  myStepper.setSpeed(20);
  myStepper1.setSpeed(20);
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available() >0)
  {
   
  }

    mot = Serial.parseInt();
   
      while (mot >0)
      {
        Serial.print("hulog:  ");
        Serial.println(mot);
        myStepper.step(-450);
        delay(10);
        mot--;
      }

   
      while (mot >0)
      {
        Serial.print("hulog:  ");
        Serial.println(mot);
        myStepper.step(-450);
        delay(10);
        mot--;
      }

}



here's my vb 2010 code, i want to connect integer 1 or 0 to arduino, but i know my code are mess. sorry

Code: [Select]
Imports System
Imports System.IO
Imports System.IO.Ports
Imports System.Threading


Public Class Form1
    Shared _continue As Boolean
    Shared _serialPort As SerialPort
    Delegate Sub SetTextCallback(ByVal [text] As String)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False

        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 Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        SerialPort1.Open()
        SerialPort1.Write("0")
        SerialPort1.Write(TextBox1.Text)
        SerialPort1.Close()


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        SerialPort1.Open()
        SerialPort1.Write("1")
        SerialPort1.Write(TextBox1.Text)
        SerialPort1.Close()

    End Sub


End Class

ieee488

You do not want to be constantly opening and closing the serial port to the Arduino.

Robin2

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

Plus what is in Reply #1 - your PC program needs to open the Serial Port, wait for the Arduino to reset and then keep the Serial Port open until it is completely finished with the Arduino.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up