Build Music instrument with PC
Build Music instrument with PC Programm By Visual Basic And Arduino
Public Class Form1
Private Sub bttcon_Click(sender As Object, e As EventArgs) Handles bttcon.Click
SerialPort1.BaudRate = cmbband.SelectedItem
SerialPort1.PortName = cmbport.SelectedItem
SerialPort1.Open()
Timer1.Start()
End Sub
Private Sub BTTdiscon_Click(sender As Object, e As EventArgs) Handles BTTdiscon.Click
SerialPort1.Close()
Timer1.Stop()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim sp As String
Dim spda As Double = 0
Dim i As String = SerialPort1.ReadExisting
Label1.Text = i.ToString
sp = Val(Label1.Text)
Select Case sp
Case Is = 1
My.Computer.Audio.Play(My.Resources.kik, AudioPlayMode.Background)
Case Is = 2
My.Computer.Audio.Play(My.Resources.sn, AudioPlayMode.Background)
Case Is = 3
My.Computer.Audio.Play(My.Resources.hh, AudioPlayMode.Background)
Case Is = 4
My.Computer.Audio.Play(My.Resources.tom, AudioPlayMode.Background)
End Select
End Sub
End Class
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int buttonPin4 = 5;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int bbb=0;
void setup() {
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3= digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
if (buttonState1 == HIGH) {
Serial.write("1");
delay(250);
} else if (buttonState2 == HIGH){
Serial.write("2");
delay(250);
}else if (buttonState3 == HIGH){
Serial.write("3");
delay(250);
}else if (buttonState4 == HIGH){
Serial.write("4");
delay(250);
}
}