so ich habe den Code jetzt mal so geändert das ich jetzt anstatt ON OFF 1 und 0 sende.
Wenn ich jetzt mir dataCOM3 ausgeben lasse bekomme ich für On 11 und für Off 0
Arduino Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
String dataCOM3 ;
char d1;
int pin = 13 ;
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hi hier ist ");
lcd.setCursor(2,1);
lcd.print("Jonathan :-)");
Serial.begin(9600);
pinMode(pin, OUTPUT);
pinMode(13, OUTPUT);
}
void loop()
{
if(Serial.available())
{
lcd.backlight();
lcd.clear();
lcd.setCursor(3,0);
dataCOM3 = Serial.readString();
d1 = dataCOM3.charAt(0);
if(d1 == '1')
{
lcd.print(dataCOM3);
digitalWrite(13, HIGH);
}
else if(d1 == '0');
{
lcd.print(dataCOM3);
digitalWrite(13, LOW);
}
}
}
Visual Studio Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Arduino_GUI4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
serialPort1.DtrEnable = false;
serialPort1.Open();
}
private void On_Click(object sender, EventArgs e)
{
//Send Comand to the Arduino to turn Pin 13 on
serialPort1.Write("1");
}
private void Off_Click(object sender, EventArgs e)
{
//Send Comand to the Arduino to turn Pin 13 OFF
serialPort1.Write("0");
}
}
}