Send low to all the 60 gpio pins on arduino when a button is pressed
-
Hi
Maybe its too much for the board in one go ? -
Can you suggest me a solution or an alternate way to do it? Because I need to have a button to turn on and off all the gpio pins of the arduino.
@jkprog
You could try with a QTimer and only turn 1 off pr timer tick
so there will be a small delay between each command.Like
class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget* parent = 0); ~MainWindow(); QTimer* timer; // <<<<<<<<<< the timer int ID = 2; // <<<<<<<<<< pin id public slots: void MyTimerSlots(); // <<<<<< for timer to call private slots: void on_pushButton_clicked(); private: Ui::MainWindow* ui; }; and in .cpp MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ID = 2; // member timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(MyTimerSlots()) ); } void MainWindow::MyTimerSlots() { QString OUT = QString ("<on, %1, 1>").arg(ID++); // create the string qDebug() << OUT; // for testing //serial.write(OUT); // activate this again. if (ID > 32) { timer->stop(); } // make sure it stops } void MainWindow::on_pushButton_clicked() { timer->start(500); // 500 ms. try less later }
and you get pr 500 ms
"<on, 2, 1>"
"<on, 3, 1>"
"<on, 4, 1>"
"<on, 5, 1>"
"<on, 6, 1>"
"<on, 7, 1>"
"<on, 8, 1>"
"<on, 9, 1>"
"<on, 10, 1>"
"<on, 11, 1>"
"<on, 12, 1>"
"<on, 13, 1>"
"<on, 14, 1>"
"<on, 15, 1>"
...So the exciting part if this works or its something else.
the test project.
https://www.dropbox.com/s/8j6lwdnrcahqd7i/serialtimer.zip?dl=0 -
Note
Write wants char * or Qbytearrayyou can do
serial.write(OUT.toStdString().c_str()); // ugly ;) -
The only change i made to the program was : serial.write(OUT.toStdString().c_str(),OUT.size() );
And its working.. :-)
Thank you :-) -
Hi,
OUT.toLatin1()
will be way cleaner.