Advertisement
Villalba2006

POST_7

Nov 24th, 2016
11,145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.61 KB | None | 0 0
  1. /*  TITULO: Control del brillo de un LED con un potenciómetro
  2.  
  3.     AUTOR:
  4.    
  5.     MARIANO DEL CAMPO GARCÍA (@2015) --> INGENIERO TÉCNICO INDUSTRIAL ESPECIALIDAD ELECTRÓNICA
  6.     - FACEBOOK: https://www.facebook.com/mariano.delcampogarcia
  7.     - TWITTER: https://twitter.com/MarianoCampoGa
  8.     - CORREO: marianodc83@gmail.com
  9.    
  10.    
  11.     DESCRIPCIÓN DEL PROGRAMA
  12.    
  13.     Con este programa regulamos el brillo del LED a medida que movamos el mando del potenciómetro.
  14.    
  15.    
  16.     ESQUEMA DE CONEXION
  17.    
  18.                                       +-----+
  19.          +----[PWR]-------------------| USB |--+
  20.          |                            +-----+  |
  21.          |         GND/RST2  [ ][ ]            |
  22.          |       MOSI2/SCK2  [ ][ ]  A5/SCL[ ] |    
  23.          |          5V/MISO2 [ ][ ]  A4/SDA[ ] |    
  24.          |                             AREF[ ] |
  25.          |                              GND[ ] |
  26.          | [ ]N/C                    SCK/13[ ] |  
  27.          | [ ]IOREF                 MISO/12[ ] |  
  28.          | [ ]RST                   MOSI/11[ ]~|  
  29.          | [ ]3V3    +---+               10[ ]~|  
  30.          | [ ]5v    -| A |-               9[ ]~|  
  31.          | [ ]GND   -| R |-               8[ ] |  
  32.          | [ ]GND   -| D |-                    |
  33.          | [ ]Vin   -| U |-               7[ ] |  
  34.          |          -| I |-               6[ ]~|  
  35.     P2   | [ ]A0    -| N |-               5[ ]~|  
  36.          | [ ]A1    -| O |-               4[ ] |  
  37.          | [ ]A2     +---+           INT1/3[ ]~|   LED(+)
  38.          | [ ]A3                     INT0/2[ ] |  
  39.          | [ ]A4/SDA  RST SCK MISO     TX>1[ ] |  
  40.          | [ ]A5/SCL  [ ] [ ] [ ]      RX<0[ ] |  
  41.          |            [ ] [ ] [ ]              |
  42.          |  UNO_R3    GND MOSI 5V  ____________/
  43.           \_______________________/
  44.  
  45.   NOTAS:
  46.    
  47.    - Cátodo(-) del LED (pata más corta) a GND a través de una R=220 omhs.
  48.    - Utilizamos un potenciómetro lineal de 10K ohms.
  49.    - Denomínamos a los terminales del potenciómetro como P1, P2 y P3 (donde P2 es el terminal central).    
  50.      - P1 conectado a VCC.
  51.      - P3 conectado a GND.
  52.        
  53. */
  54.  
  55.  
  56.   const int LED = 3; // Pin digital con PWM
  57.   const int potenciometro = 0; // Pin analógico
  58.  
  59.   int brillo = 0; // Variable que acumula el brillo
  60.  
  61.   void setup()
  62.   {
  63.     pinMode(LED, OUTPUT); // Pin digital 3 como salida
  64.   }
  65.  
  66.   void loop()
  67.   {
  68.       brillo = (analogRead(potenciometro))/4; // Leemos el valor de A0 y lo guardamos en brillo
  69.       analogWrite(LED, brillo); // Escribimos el valor del brillo en el pin 3 (PWM)
  70.       delay(20);
  71.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement