Devices & Components
Arduino Uno Rev3
LED (generic)
Jumper wires (generic)
Breadboard (generic)
Hardware & Tools
Materia 101
Software & Tools
Visual Studio 2015
Arduino IDE
Project description
Code
vb.net code
vb.net
1Imports System.IO 2Imports System.IO.Ports 3 4Imports System.Threading 5 6Public Class Form3 7 8Shared _continue As Boolean 9 10Shared _serialPort As SerialPort 11 12Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() 13 14SerialPort1.PortName = "com3" 15 16SerialPort1.BaudRate = 9600 17 18SerialPort1.DataBits = 8 19 20SerialPort1.Parity = Parity.None 21 22SerialPort1.StopBits = StopBits.One 23 24SerialPort1.Handshake = Handshake.None 25 26SerialPort1.Encoding = System.Text.Encoding.Default 27 28End Sub 29 30Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click End 31 32End Sub 33 34Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Open() 35 36SerialPort1.Write("1") 37 38SerialPort1.Close() 39 40End Sub
vb.net code
vb.net
1Imports System.IO 2Imports System.IO.Ports 3 4Imports System.Threading 5 6Public Class Form3 7 8Shared _continue As Boolean 9 10Shared _serialPort As SerialPort 11 12Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() 13 14SerialPort1.PortName = "com3" 15 16SerialPort1.BaudRate = 9600 17 18SerialPort1.DataBits = 8 19 20SerialPort1.Parity = Parity.None 21 22SerialPort1.StopBits = StopBits.One 23 24SerialPort1.Handshake = Handshake.None 25 26SerialPort1.Encoding = System.Text.Encoding.Default 27 28End Sub 29 30Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click End 31 32End Sub 33 34Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Open() 35 36SerialPort1.Write("1") 37 38SerialPort1.Close() 39 40End Sub
Code
csharp
1int ledPin = 13; 2int led1Pin = 12; 3 4void setup() { 5 6Serial.begin(9600); 7 8pinMode(13, OUTPUT); 9 10digitalWrite(13, LOW); 11 12pinMode(12, OUTPUT); 13 14digitalWrite(10, LOW); //turn off LED1 15 16} 17 18void loop() 19 20{ 21 22while (Serial.available() == 0); 23 24int val = Serial.read() - '0'; 25 26if (val == 1) 27 28{ 29 30digitalWrite(12, HIGH); 31 32} 33 34else if (val == 0) // 35 36{ 37 38digitalWrite(12, LOW); } 39 40else if (val == 2) 41 42{ 43 44digitalWrite(13, HIGH); 45 46} 47 48else if (val == 3) 49 50{ 51 52digitalWrite(13, LOW); 53 54} 55 56else 57 58{ 59 60//val = val; 61 62} 63 64Serial.println(val); 65 66Serial.flush(); // clear serial port 67 68}
Comments
Only logged in users can leave comments