Hello im i have a C# script for xamarin android app and i want to send an on or off signal as 1 or 0.
Now i dont know where to start because i have looked at some basic explanation of UDP for arduino but still cant figure it out.
Im using an arduino UNO and 1 LED with a 220 ohm resistor i want to turn on via my C# code which is a android app i emulate via my computer using Visual studio community 2019.
So my question is how can my arduino UNO receive the 1 or 0 i send and via that turn on/off the LED.
Thanks for reading already
My .cs code of my app
namespace App2
{
public partial class MainPage : ContentPage
{
string IP = "172.29.38.80";
int port = 8888;
string data = "";
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
public MainPage()
{
}
private void Lichtaan()
{
data = "1";
var ip = IPAddress.Parse(IP);
var ep = new IPEndPoint(ip, port);
Byte[] packetData = Encoding.ASCII.GetBytes(data);
client.SendTo(packetData, ep);
}
private void Lichtuit()
{
data = "0";
var ip = IPAddress.Parse(IP);
var ep = new IPEndPoint(ip, port);
Byte[] packetData = Encoding.ASCII.GetBytes(data);
client.SendTo(packetData, ep);
}
void AanButton_Clicked(object sender, EventArgs e)
{
Lichtaan();
}
void UitButton_Clicked(object sender, EventArgs e)
{
Lichtuit();
}
}
}
My xaml code of my app
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App2.MainPage">
<StackLayout>
<Frame BackgroundColor="#289128" Padding="24" CornerRadius="0">
<Label Text="Aruidno App" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</Frame>
<Label Text="Lamp 1" HorizontalTextAlignment="Center" TextColor="black" FontSize="36"/>
<Button Text="Aan" x:Name="aanButton" Clicked="AanButton_Clicked"/>
<Button Text="Uit" x:Name="uitButton" Clicked="UitButton_Clicked"/>
</StackLayout>
</ContentPage>