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... ») |
|||
Ligne 1 : | Ligne 1 : | ||
<source lang=c> | <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 9 : | ||
pinMode(position,INPUT); | pinMode(position,INPUT); | ||
} | } | ||
− | |||
bool Bouton::lireValeur(){ | bool Bouton::lireValeur(){ | ||
if(this->isPullUp==1){ | if(this->isPullUp==1){ | ||
Ligne 25 : | Ligne 17 : | ||
} | } | ||
} | } | ||
+ | </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 du 7 mars 2017 à 10:54
// 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_ */