Contact shield wifi tcp vb.net Android

c++

#include <SPI.h>
#include <WiFi.h>
#include <TimedAction.h>


char ssid[] = "yourNetwork";     
char pass[] = "secretPassword"; 




int keyIndex = 0;              

int status = WL_IDLE_STATUS;
WiFiServer server(80);




TimedAction timedAction = TimedAction(800 ,off);

#define pin0 3
#define pin1 4
#define pin2 5
#define pin3 6

#define on  0
#define of 1

void setup() {

	Serial.begin(9600);     
	Serial.println("stert");

	digitalWrite(pin0, on);
	digitalWrite(pin1, on);
	digitalWrite(pin2, on);
	digitalWrite(pin3,on);

	pinMode(pin0, OUTPUT);      
	pinMode(pin1, OUTPUT);   
	pinMode(pin2, OUTPUT);      
	pinMode(pin3, OUTPUT);  


	if (WiFi.status() == WL_NO_SHIELD) {
		Serial.println("WiFi shield not present"); 
		while(true);      
	} 


	while ( status != WL_CONNECTED) { 

		Serial.print("Attempting to connect to Network named: ");
		Serial.println(ssid);               


		status = WiFi.begin(ssid, pass);


		delay(10000);
	} 
	server.begin();                          
	printWifiStatus();                      
}

 String c;
void loop() {

	 

	WiFiClient client = server.available();   
	client.setTimeout(5);



	if (client) {   


		while (client.connected()) {  


			c = client.readString();

			
		


			if (c=="10") {
				r1_r();
				l_off();
				client.stop();
			}
			else if (c=="11")
			{
				r2_r();
				l_off();
				client.stop();
			}
			else if (c=="14")
			{
				r1_l();
				r_off();
				client.stop();
			}
			
			
			else if (c=="17")
			{
				r2_l();
				r_off();
				client.stop();
			}
			else if (c=="4")
			{
				r1_r();
				r1_l();
				client.stop();
			}
			else if (c=="8")
			{
					r2_r();
				r2_l();
				client.stop();
			}

			else if (c=="7")
			{
				r1_r();
				r2_l();
				client.stop();
			}

			else if (c=="5")
			{
				r2_r();
				r1_l();
				client.stop();
			}
				else if (c=="20")
			{
l_off();
r_off();
				client.stop();
			}

			Serial.println(c);
			/*Serial.println(c.length());*/
		
		}


	}

	timedAction.check();

}





void r1_r(){
		
	digitalWrite(pin0, of);
	digitalWrite(pin1, on);
}
void r2_r(){
		
	digitalWrite(pin0, on);
	digitalWrite(pin1, of);
}
void r1_l(){
		
	digitalWrite(pin2, of);
	digitalWrite(pin3, on);
}
void r2_l(){
		
	digitalWrite(pin2, on);
	digitalWrite(pin3, of);
}


void r_off(){
		digitalWrite(pin0, on);
	digitalWrite(pin1, on);

}
void l_off(){
		digitalWrite(pin2, on);
	digitalWrite(pin3, on);

}


void off(){
	if (c=="")
	{
r_off();
	l_off();
	}

	c="";

}

void printWifiStatus() {

	Serial.print("SSID: ");
	Serial.println(WiFi.SSID());


	IPAddress ip = WiFi.localIP();
	Serial.print("IP Address: ");
	Serial.println(ip);


	long rssi = WiFi.RSSI();
	Serial.print("signal strength (RSSI):");
	Serial.print(rssi);
	Serial.println(" dBm");


	Serial.println(ip);


}

vb.net

Imports System.Net.Sockets
Imports System.Text
Imports Microsoft.Xna
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Input
Imports Microsoft.Xna.Framework.GamerServices
Imports Microsoft.Xna.Framework.Content
Public Class Form1
    Dim oTcpClient As New TcpClient
    Dim oNetworkStream As NetworkStream

    Dim postBytes As Byte()

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 50
        Timer1.Enabled = True
        Timer2.Interval = 700
        Timer2.Enabled = False
    End Sub


    Sub snd(ByVal s As String)

        Try
            oTcpClient = New TcpClient
            oTcpClient.Connect("192.168.1.73", 80)
            oNetworkStream = oTcpClient.GetStream
            If oTcpClient.Connected Then
                postBytes = Encoding.ASCII.GetBytes(s)
                oNetworkStream.Write(postBytes, 0, postBytes.Length)
                oNetworkStream.Flush()

            End If
            oTcpClient.Close()
        Catch ex As Exception

        End Try


    End Sub




    Dim RightY, LeftY As Int16
    Dim Signal, signal_old As Int16
    Dim iss As Boolean = False
    '  Timer1.Interval = 50
    Public Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Dim currentState As GamePadState = GamePad.GetState(PlayerIndex.One)



        Signal = 0
        RightY = (currentState.ThumbSticks.Right.Y.ToString("0"))
        LeftY = (currentState.ThumbSticks.Left.Y.ToString("0"))





        If RightY > 0 Then

            Signal = 1 '1

            La_RightY_u.BackColor = Drawing.Color.Red
            La_RightY_d.BackColor = Drawing.Color.Black
        ElseIf RightY < 0 Then


            Signal = 2 '2

            La_RightY_d.BackColor = Drawing.Color.Red
            La_RightY_u.BackColor = Drawing.Color.Black





        Else
            Signal = 11

            La_RightY_u.BackColor = Drawing.Color.Black
            La_RightY_d.BackColor = Drawing.Color.Black
        End If





        If LeftY > 0 Then
            Signal += 3 '3+4+5

            La_LeftY_u.BackColor = Drawing.Color.Red
            La_LeftY_d.BackColor = Drawing.Color.Black
        ElseIf LeftY < 0 Then
            Signal += 6 '6+7+8
            La_LeftY_d.BackColor = Drawing.Color.Red
            La_LeftY_u.BackColor = Drawing.Color.Black
        Else

            Signal += 9 '6+7+8

            La_LeftY_u.BackColor = Drawing.Color.Black
            La_LeftY_d.BackColor = Drawing.Color.Black
        End If


        If Signal <> signal_old Then
            snd(Signal)

            signal_old = Signal
            Console.WriteLine(Signal)
            Me.Text = Signal


            If Signal = 20 Then
                Timer2.Enabled = False
            Else
                Timer2.Enabled = True

            End If


        End If



    End Sub

    Private Sub Timer2_Tick(sender As System.Object, e As System.EventArgs) Handles Timer2.Tick

        snd(Signal)
    End Sub


End Class

Projects.rar (971 KB)

Do you want this moved to "Exhibition"?

Please move the topic to the appropriate forum

I do not know the English language

translate Google