Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********** Proyecto **********
- * Laboratorio 4
- * Autor: Josue Mauricio Hurtado Mosquera
- * Descripcion:
- * Controlar un LED RGB desde el Arduino, vía PWM con 3 potenciómetros, uno para cada color.
- */
- /********** Constantes **********/
- #define POT1 A0
- #define POT2 A1
- #define POT3 A2
- #define TOTLED 3 // Total LEDs
- /********** Variables **********/
- int led[TOTLED] = {3, 4, 5};
- /********** Configuracion **********/
- void setup() {
- // put your setup code here, to run once:
- int pos=0;
- while (pos < TOTLED){ //se realiza un while para que recorra los pines del arreglo y los configure como OUTPUT
- pinMode(led[pos], OUTPUT);
- pos=pos+1;
- }
- pinMode(POT1, INPUT);//se configuran los pines de los potenciometros como INPUT
- pinMode(POT2, INPUT);
- pinMode(POT3, INPUT);
- } // end setup()
- /********** Ciclo Principal **********/
- void loop() {
- // put your main code here, to run repeatedly:
- valorR = analogRead(POT1); //se lee el valor dado por el potenciometro
- valorA = analogRead(POT2);
- valorV = analogRead(POT3);
- analogWrite(3,valorR); // Cambiar la intensidad de iluminacion del LED segun el valor leido
- analogWrite(4,valorA);
- analogWrite(5,valorV);
- } // end loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement