Cours:Arduino2017 : Différence entre versions

De troyesGEII
Aller à : navigation, rechercher
 
Ligne 1 : Ligne 1 :
 +
<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>
 
<source lang=c>
 
// Bouton.cpp
 
// Bouton.cpp

Version actuelle datée du 7 mars 2017 à 11: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_ */