Hey,
bin gerade dabei eine GUI mit Qt für mein Arduino zu programmieren.
Soweit so gut
Ich habe es hinbekommen (durch langes suchen im Internet :o ) eine LED Ein- und Auszuschalten.
Meine frage nun ist, wie kann ich eine zweite LED bzw. in diesem Fall GPIO ansteuern?
Mein Code sieht in der Arduino Software wie folgt aus:
#define PIN_LED D7
void setup()
{
pinMode(PIN_LED, OUTPUT);
analogWrite(PIN_LED, 0);
Serial.begin(9600);
}
void loop()
{
if (Serial.available())
{
const int led_D7 = Serial.parseInt();
if(led_D7 ==1)
{
digitalWrite(PIN_LED, HIGH);
}
else
{
digitalWrite(PIN_LED, LOW);
}
}
}
In Qt:
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
arduino_is_available = false;
arduino_port_name = "";
arduino = new QSerialPort;
qDebug() << "Number of available ports: " << QSerialPortInfo::availablePorts().length();
foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
qDebug() << "Has vendor ID: " << serialPortInfo.hasVendorIdentifier();
if(serialPortInfo.hasVendorIdentifier()){
qDebug() << "Vendor ID: " << serialPortInfo.vendorIdentifier();
}
qDebug() << "Has Product ID: " << serialPortInfo.hasProductIdentifier();
if(serialPortInfo.hasProductIdentifier()){
qDebug() << "Product ID: " << serialPortInfo.productIdentifier();
}
}
foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
if(serialPortInfo.hasVendorIdentifier() && serialPortInfo.hasProductIdentifier()){
if(serialPortInfo.vendorIdentifier() == arduino_uno_vendor_id){
if(serialPortInfo.productIdentifier() == arduino_uno_product_id){
arduino_port_name = serialPortInfo.portName();
arduino_is_available = true;
}
}
}
}
if(arduino_is_available){
// open and configure the serialport
arduino->setPortName(arduino_port_name);
arduino->open(QSerialPort::WriteOnly);
arduino->setBaudRate(QSerialPort::Baud9600);
arduino->setDataBits(QSerialPort::Data8);
arduino->setParity(QSerialPort::NoParity);
arduino->setStopBits(QSerialPort::OneStop);
arduino->setFlowControl(QSerialPort::NoFlowControl);
}else{
// give error message if not available
QMessageBox::warning(this, "Port error", "Couldn't find the Arduino!");
}
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_encenderPushButton_clicked()
{
if(arduino->isWritable()){
arduino->write("1");
}else{
qDebug() << "Couldn't write to serial!";
}
}
void Widget::on_apagarPushButton_clicked()
{
if(arduino->isWritable()){
arduino->write("0");
}else{
qDebug() << "Couldn't write to serial!";
}
}