hello;
i have problem arduino or c# codes.
if push button1 arduino send c# value on serial comminication, if press button2, button3 or button4 arduino can not send anything. cant find problem :/
best regards.
arduino codes:
c# codes
i have problem arduino or c# codes.
if push button1 arduino send c# value on serial comminication, if press button2, button3 or button4 arduino can not send anything. cant find problem :/
best regards.
arduino codes:
code: [select]
char x;
char b;
int button1 = digitalread(2);
int button2 = digitalread(3);
int button3 = digitalread(4);
int button4 = digitalread(5);
void setup()
{
serial.begin(9600);
pinmode(2, input_pullup);
pinmode(3, input_pullup);
pinmode(4, input_pullup);
pinmode(5, input_pullup);
}
void loop()
{
if(serial.available()>0)
x=serial.read();
if(x=='a')
{
if (button1 == high)
{
button1 = digitalread(2);
serial.println(1);
delay(100);
}
}
else if(x=='b')
{
if (button2 == high)
{
button2 = digitalread(3);
serial.println(2);
delay(100);
}
}
else if(x=='c')
{
if (button3 == high)
{
button3 = digitalread(4);
serial.println(3);
delay(100);
}
}
else if(x=='d')
{
if (button4 == high)
{
button4 = digitalread(5);
serial.println(4);
delay(100);
}
}
}
c# codes
code: [select]
private void timer1_tick(object sender, eventargs e)
{
try
{
seriport.write("a");
int button1 = convert.toint32(seriport.readexisting());
if (button1 == 1)
{
lstbuttonlar.items.add("button 1 basıldı! " + datetime.now);
}
seriport.write("b");
int button2 = convert.toint16(seriport.readexisting());
if (button2 == 2)
{
lstbuttonlar.items.add("button 2 basıldı! " + datetime.now);
}
seriport.write("c");
int button3 = convert.toint16(seriport.readexisting());
if (button3 == 3)
{
lstbuttonlar.items.add("button 3 basıldı! " + datetime.now);
}
seriport.write("d");
int button4 = convert.toint16(seriport.readexisting());
if (button4 == 4)
{
lstbuttonlar.items.add("button 4 basıldı! " + datetime.now);
}
system.threading.thread.sleep(100);
}
catch (exception ex)
{
}
}
what see when @ values arduino sends serial monitor?
Arduino Forum > Using Arduino > Programming Questions > Button Control C# .NET
arduino
Comments
Post a Comment