Cours:Arduino2017 : Différence entre versions
(Page créée avec « <source lang=c> →* Bouton.cpp * * Created on: 7 mars 2017 * Author: jacquo03 : #include "Bouton.h" #include "Arduino.h" Bouton::Bouton(int p, bool ispullup... ») |
|||
| (Une révision intermédiaire par le même utilisateur non affichée) | |||
| Ligne 1 : | Ligne 1 : | ||
<source lang=c> | <source lang=c> | ||
/* | /* | ||
| − | * | + | * Lampe.h |
| − | |||
| − | |||
| − | |||
*/ | */ | ||
| + | #ifndef LAMPE_H_ | ||
| + | #define LAMPE_H_ | ||
| + | |||
| + | class Lampe { | ||
| + | protected: | ||
| + | int position; | ||
| + | public: | ||
| + | Lampe(int p); | ||
| + | void allumer(); | ||
| + | void eteindre(); | ||
| + | void setValeur(int v); | ||
| + | }; | ||
| + | |||
| + | #endif /* LAMPE_H_ */ | ||
| + | </source> | ||
| + | |||
| + | <source lang=c> | ||
| + | /* | ||
| + | * Lampe.cpp | ||
| + | */ | ||
| + | |||
| + | #include "Lampe.h" | ||
| + | #include "Arduino.h" | ||
| + | |||
| + | Lampe::Lampe(int p) { | ||
| + | // TODO Auto-generated constructor stub | ||
| + | position=p; | ||
| + | pinMode(position,OUTPUT); | ||
| + | } | ||
| + | |||
| + | void Lampe::allumer() | ||
| + | { | ||
| + | setValeur(100); | ||
| + | } | ||
| + | |||
| + | void Lampe::eteindre() | ||
| + | { | ||
| + | setValeur(0); | ||
| + | } | ||
| + | |||
| + | void Lampe::setValeur(int v) | ||
| + | { | ||
| + | if (v==0) digitalWrite(position,0); | ||
| + | else digitalWrite(position,1); | ||
| + | } | ||
| + | </source> | ||
| + | |||
| + | <source lang=c> | ||
| + | // Bouton.cpp | ||
#include "Bouton.h" | #include "Bouton.h" | ||
#include "Arduino.h" | #include "Arduino.h" | ||
| − | |||
Bouton::Bouton(int p, bool ispullup) | Bouton::Bouton(int p, bool ispullup) | ||
{ | { | ||
| Ligne 16 : | Ligne 61 : | ||
pinMode(position,INPUT); | pinMode(position,INPUT); | ||
} | } | ||
| − | |||
bool Bouton::lireValeur(){ | bool Bouton::lireValeur(){ | ||
if(this->isPullUp==1){ | if(this->isPullUp==1){ | ||
| Ligne 25 : | Ligne 69 : | ||
} | } | ||
} | } | ||
| + | </source> | ||
| + | |||
| + | <source lang=c> | ||
| + | //fichier ino | ||
| + | #include "Arduino.h" | ||
| + | #include "LampeVariable.h" | ||
| + | |||
| + | LampeVariable lv(9); | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | for (int i=0;i<100;i=i+10) | ||
| + | { | ||
| + | lv.setValeur(i); | ||
| + | delay(100); | ||
| + | } | ||
| + | } | ||
| + | </source> | ||
| + | |||
| + | <source lang=c> | ||
| + | // LampeVariable.cpp | ||
| + | #include "LampeVariable.h" | ||
| + | #include "Arduino.h" | ||
| + | |||
| + | LampeVariable::LampeVariable(int p) : Lampe(p) { | ||
| + | } | ||
| + | |||
| + | void LampeVariable::setValeur(int v) | ||
| + | { | ||
| + | analogWrite(position,v); | ||
| + | } | ||
| + | </source> | ||
| + | |||
| + | <source lang=c> | ||
| + | /* | ||
| + | * LampeVariable.h | ||
| + | */ | ||
| + | |||
| + | #ifndef LAMPEVARIABLE_H_ | ||
| + | #define LAMPEVARIABLE_H_ | ||
| + | |||
| + | #include "Lampe.h" | ||
| + | |||
| + | class LampeVariable: public Lampe { | ||
| + | public: | ||
| + | LampeVariable(int p); | ||
| + | void setValeur(int val); | ||
| + | }; | ||
| + | #endif /* LAMPEVARIABLE_H_ */ | ||
</source> | </source> | ||
Version actuelle datée du 7 mars 2017 à 10:55
/*
* Lampe.h
*/
#ifndef LAMPE_H_
#define LAMPE_H_
class Lampe {
protected:
int position;
public:
Lampe(int p);
void allumer();
void eteindre();
void setValeur(int v);
};
#endif /* LAMPE_H_ */
/*
* Lampe.cpp
*/
#include "Lampe.h"
#include "Arduino.h"
Lampe::Lampe(int p) {
// TODO Auto-generated constructor stub
position=p;
pinMode(position,OUTPUT);
}
void Lampe::allumer()
{
setValeur(100);
}
void Lampe::eteindre()
{
setValeur(0);
}
void Lampe::setValeur(int v)
{
if (v==0) digitalWrite(position,0);
else digitalWrite(position,1);
}
// Bouton.cpp
#include "Bouton.h"
#include "Arduino.h"
Bouton::Bouton(int p, bool ispullup)
{
position = p;
isPullUp = ispullup;
pinMode(position,INPUT);
}
bool Bouton::lireValeur(){
if(this->isPullUp==1){
return !digitalRead(this->position);
}
else{
return digitalRead(this->position);
}
}
//fichier ino
#include "Arduino.h"
#include "LampeVariable.h"
LampeVariable lv(9);
void setup()
{
}
void loop()
{
for (int i=0;i<100;i=i+10)
{
lv.setValeur(i);
delay(100);
}
}
// LampeVariable.cpp
#include "LampeVariable.h"
#include "Arduino.h"
LampeVariable::LampeVariable(int p) : Lampe(p) {
}
void LampeVariable::setValeur(int v)
{
analogWrite(position,v);
}
/*
* LampeVariable.h
*/
#ifndef LAMPEVARIABLE_H_
#define LAMPEVARIABLE_H_
#include "Lampe.h"
class LampeVariable: public Lampe {
public:
LampeVariable(int p);
void setValeur(int val);
};
#endif /* LAMPEVARIABLE_H_ */