So I am making a user interface on vb 2010 that allows the user to type in a textbox the PWM they want a value between 0-255. I want to be able to take the value and change it as much as i want but there seems to be a problem i am only able to send one value without needing to debug the program again. The LED I am using as the test doesn't seem to be responding with the equivalent level brightness for the PWM that i use in the textbox. I hope to be able to control this with 8 separate relays as the end goal using some sort of switch statement. Any help would be very nice my current code:
VB
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Dim SerialPort1 As SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1 = New SerialPort
SerialPort1.PortName = "COM4"
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
SerialPort1.Open()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim input As String
Dim returnvalue As String
input = TextBox1.Text
returnvalue = input
SerialPort1.Write(input)
SerialPort1.Close()
MessageBox.Show(returnvalue)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim a As Integer
a = SerialPort1.ReadChar()
MessageBox.Show(a)
End Sub
End Class
Arduino
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pins:
int thisPin = 2;
pinMode(thisPin, OUTPUT);
}
void loop() {
int inByte= 0;
int V1;
if (Serial.available()) {
inByte = Serial.read();
V1 = inByte;
analogWrite(2, V1);
}
}