Cours:Arduino2017

De troyesGEII
Aller à : navigation, rechercher
// 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_ */