marcmerlin / ArduinoOnPc-FastLED-GFX-LEDMatrix

Run code for SmartMatrix, Adafruit-GFX-Library, FastLED (2D), and LEDMatrix on linux/Raspberry Pi with X11, SDL, or on top of RGBPanels
http://marc.merlins.org/perso/arduino/post_2020-01-01_Running-FastLED_-Adafruit_GFX_-and-LEDMatrix-code-on-High-Resolution-RGBPanels-with-a-Raspberry-Pi.html
GNU Lesser General Public License v3.0
29 stars 3 forks source link

A way to simulate GPIO input (pressed button) ? #8

Closed Lecrapouille closed 2 years ago

Lecrapouille commented 2 years ago

How to simulate this kind of code ?

bool bp_on;
void setup() {
  pinMode(3, INPUT);
}

void loop() {
  bp_on = digitalRead(3);
}

Currently, it just displays:

pinMode pin 3 set to : INPU
pinMode pin 4 set to : INPU

But no interaction possible to simulate button pressed.

By the way, typo at https://github.com/marcmerlin/ArduinoOnPc-FastLED-GFX-LEDMatrix/blob/master/src/cores/arduino/wiring_digital.cpp#L19 should be INPUT (no INPU).

Full ino code:

bool bp_on;                  // variable associee au bouton poussoire on
bool bp_off;                 // variable associee au bouton poussoire off
enum Etat { MARCHE, ARRET }; // Declaration des etats possibles
Etat etatCourant;            // variable associee à l'etat courant

void setup()
{
    pinMode(3, INPUT);    // La pin 3 est definie comme une entree (bouton poussoire)
    pinMode(4, INPUT);    // La pin 4 est definie comme une entree (bouton poussoire)
    etatCourant = MARCHE; // Etat initial
}

void loop()
{
    // Mise a jour des entrees
    bp_on = digitalRead(3);
    bp_off = digitalRead(4);

    // Gestion de l'evolution des etats
    switch (etatCourant)
    {
    case MARCHE:
        // Action etat Marche
        //...

        // Transition vers l'etat ARRET
        if (bp_off) {
            etatCourant = ARRET;
        }
        break;

    case ARRET :
        // Action etat Arret
        //...

        //Transition vers l'etat MARCHE
        if (bp_on) {
            etatCourant = MARCHE;
        }
        break;
    }
}
marcmerlin commented 2 years ago

Good question, this part of the code I did not write and I don't use, it was forked from https://github.com/ChrisMicro/ArduinoOnPc I suggest you ask file the issue in https://github.com/ChrisMicro/ArduinoOnPc , sorry that I can't help with this