Advertisement
Abelsor

Led_Potenciometro_POO

May 10th, 2024
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. /////////////////////////// Class Potenciometro  ////////////////////////
  2.  
  3. class Potenciometro{
  4.     public:
  5.         Potenciometro();
  6.         Potenciometro(byte);
  7.         virtual ~Potenciometro();
  8.  
  9.         // Metodos
  10.         float escalar();
  11.         float getLectura();
  12.        
  13.     private:
  14.         byte pin;
  15.         float lectura;
  16. };
  17.  
  18. Potenciometro::Potenciometro(){
  19.  
  20. }
  21.  
  22. Potenciometro::Potenciometro(byte _pin){
  23.     pin = _pin;
  24. }
  25.  
  26. Potenciometro::~Potenciometro(){
  27.  
  28. }
  29.  
  30. float Potenciometro::getLectura(){
  31.     return analogRead(pin);
  32. }
  33.  
  34. float Potenciometro::escalar()
  35. {
  36.     return map(Potenciometro::getLectura(),0,1023,0,255);
  37. }
  38.  
  39.  
  40. /////////////////////////// Class Led  ////////////////////////
  41. class Led{
  42.     public:
  43.         Led();
  44.         Led(byte);
  45.         virtual ~Led();
  46.  
  47.         // Metodos
  48.         void setIntensidad(float);
  49.  
  50.     private:
  51.         byte pin;
  52.         float intensidad;
  53. };
  54.  
  55. Led::Led(){
  56.  
  57. }
  58.  
  59. Led::Led(byte _pin){
  60.   pin = _pin;
  61.   pinMode(_pin, OUTPUT);
  62. }
  63.  
  64. Led::~Led(){
  65.  
  66. }
  67.  
  68. void Led::setIntensidad(float _intensidad){
  69.   intensidad = _intensidad;
  70.   analogWrite(pin,_intensidad);
  71. }
  72.  
  73.  
  74. ///////////////////////////////////////////////////////////////
  75. Led led(6);
  76. Potenciometro p1(A0);
  77.  
  78. void setup()
  79. {
  80.     Serial.begin(9600);
  81. }
  82.  
  83. void loop()
  84. {
  85.     led.setIntensidad(p1.getLectura());    
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement