Cours:PooTD1 ledsbps : Différence entre versions
(→travail à réaliser) |
(→classe Bouton) |
||
| Ligne 82 : | Ligne 82 : | ||
=classe Bouton= | =classe Bouton= | ||
| + | |||
| + | |||
| + | {|style="vertical-align:middle; width:100%; text-align:left; " | ||
| + | |- | ||
| + | | {{boîte déroulante/début|titre=bouton.h}} | ||
| + | <source lang=cpp> | ||
| + | #ifndef BOUTON_H | ||
| + | #define BOUTON_H | ||
| + | |||
| + | class Bouton | ||
| + | { | ||
| + | public: | ||
| + | Bouton(); | ||
| + | int getValue(); | ||
| + | }; | ||
| + | |||
| + | #endif // BOUTON_H | ||
| + | </source> | ||
| + | {{boîte déroulante/fin}} | ||
| + | || {{boîte déroulante/début|titre=bouton.cpp}} | ||
| + | <source lang=cpp> | ||
| + | #include "bouton.h" | ||
| + | #include <pigpio.h> | ||
| + | #include <QDebug> | ||
| + | |||
| + | Bouton::Bouton() | ||
| + | { | ||
| + | qDebug()<<"création d'un bouton"; | ||
| + | gpioInitialise(); | ||
| + | gpioSetMode(16,PI_INPUT); | ||
| + | |||
| + | } | ||
| + | |||
| + | int Bouton::getValue() | ||
| + | { | ||
| + | int etat = gpioRead(16); | ||
| + | qDebug()<<"je suis dans l'état : "<<etat; | ||
| + | return etat; | ||
| + | } | ||
| + | </source> | ||
| + | {{boîte déroulante/fin}} | ||
| + | |} | ||
Version du 28 août 2025 à 09:54
Retour à la liste des Tds
Sommaire
1ère classe
Préparation du projet
- Créer un nouveau projet de type "QT en console"
- Choisir le kit "piTp"
- ajouter à la fin du fichier .pro la ligne
LIBS += -lpigpio - Dans l'arborescence de votre projet,
- Ajouter des fichiers existants
classe Lampe
| lampe.h #ifndef LAMPE_H
#define LAMPE_H
#include <QObject>
class Lampe
{
public:
Lampe();
void allumer();
private:
int numGpio;
};
#endif // LAMPE_H
|
lampe.cpp #include "lampe.h"
#include <pigpio.h>
Lampe::Lampe()
{
gpioInitialise();
gpioSetMode(5,PI_OUTPUT);
}
void Lampe::allumer()
{
gpioWrite(5,true);
}
|
#include <QCoreApplication>
#include "lampe.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Lampe l1{};
l1.allumer();
return a.exec();
}
clignotement
#include <unistd.h>
using namespace std;
...
usleep( dureeEnMillisecondes );
sleep( dureeEnSecondes );
travail à réaliser
- plusieurs leds
classe Bouton
| bouton.h #ifndef BOUTON_H
#define BOUTON_H
class Bouton
{
public:
Bouton();
int getValue();
};
#endif // BOUTON_H
|
bouton.cpp #include "bouton.h"
#include <pigpio.h>
#include <QDebug>
Bouton::Bouton()
{
qDebug()<<"création d'un bouton";
gpioInitialise();
gpioSetMode(16,PI_INPUT);
}
int Bouton::getValue()
{
int etat = gpioRead(16);
qDebug()<<"je suis dans l'état : "<<etat;
return etat;
}
|