make sure you drag the serial port control icon from the toolbox onto your form

3
Make sure you drag the Serial Port control icon from the Toolbox onto your form. It should have the name SerialPort1 '------------ START OF VB 2010 CODE ----------------- ' NOTE: I am using COM10 so you need to change the Visual Basic code to match your COM port Imports System.IO Imports System.IO.Ports Imports System.Threading Public Class Form1 Shared _continue As Boolean Shared _serialPort As SerialPort Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() SerialPort1.PortName = "com10" 'change com port to match your Arduino port 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! End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArg Handles Button1.Click SerialPort1.Open() SerialPort1.Write("1") SerialPort1.Close() End Sub

Upload: oscarin696

Post on 06-Oct-2015

5 views

Category:

Documents


0 download

DESCRIPTION

Sure products

TRANSCRIPT

Make sure you drag the Serial Port control icon from the Toolbox onto your form. It should have the nameSerialPort1

'------------ START OF VB 2010 CODE -----------------' NOTE: I am using COM10 so you need to change the Visual Basic code to match your COM port

Imports System.IOImports System.IO.PortsImports System.Threading

Public Class Form1Shared _continue As BooleanShared _serialPort As SerialPort

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadSerialPort1.Close()SerialPort1.PortName = "com10" 'change com port to match your Arduino portSerialPort1.BaudRate = 9600SerialPort1.DataBits = 8SerialPort1.Parity = Parity.NoneSerialPort1.StopBits = StopBits.OneSerialPort1.Handshake = Handshake.NoneSerialPort1.Encoding = System.Text.Encoding.Default 'very important!End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickSerialPort1.Open()SerialPort1.Write("1")SerialPort1.Close()End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickSerialPort1.Open()SerialPort1.Write("0")SerialPort1.Close()End SubEnd Class'------------ END OF VB 2010 CODE -----------------

//------------- START OF ARDUINO SKETCH -----------------//// Mixed by: Hazim Bitar// Based on: Science Guy 14 youTube tutorial http://youtu.be/g0pSfyXOXj8

int ledPin = 13; // the number of the LED pin

void setup() {Serial.begin(9600); // set serial speedpinMode(ledPin, OUTPUT); // set LED as outputdigitalWrite(ledPin, LOW); //turn off LED}

void loop(){while (Serial.available() == 0); // do nothing if nothing sentint val = Serial.read() - '0'; // deduct ascii value of '0' to find numeric value of sent number

if (val == 1) { // test for command 1 then turn on LEDSerial.println("LED on");digitalWrite(ledPin, HIGH); // turn on LED}else if (val == 0) // test for command 0 then turn off LED{Serial.println("LED OFF");digitalWrite(ledPin, LOW); // turn off LED}else // if not one of above command, do nothing{//val = val;}Serial.println(val);Serial.flush(); // clear serial port}

//------------- END OF ARDUINO SKETCH -----------------http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express