Programas de Arduino Con Rgb

Programa, que lee los datos del potenciómetro mediante el puerto serie (sin usar un LED) y lo muestra en el equipo. // h

Views 127 Downloads 1 File size 973KB

Report DMCA / Copyright

DOWNLOAD FILE

Recommend stories

Citation preview

Programa, que lee los datos del potenciómetro mediante el puerto serie (sin usar un LED) y lo muestra en el equipo. // http://www.fibidi.com/?p=321 // void setup() { Serial.begin(9600); at 9600 bits per second }

// initialize serial communication

void loop() { int sensorValue = analogRead(A0); analog pin 0 Serial.println(sensorValue); you read delay(1); reads for stability } //

http://www.fibidi.com/?p=321

// read the input on // print out the value // delay in between

//

Programa, que lee los datos del potenciómetro (en el rango de 0 a 1.023), los ajusta a la gama de puertos PWM (0-255) y controla el brillo de la luz LED. //

http://www.fibidi.com/?p=321

//

int led = 6; int i; void setup() { Serial.begin(9600); pinMode(led, OUTPUT); } void loop() { int sensorValue = analogRead(A0); i = map(sensorValue, 0, 1023, 0, 255); Serial.println(i); analogWrite(led, i); delay(1); }

//

http://www.fibidi.com/?p=321

//

Programa, en el que cada uno de los colores (rojo, verde, azul) está soportado por un potenciómetro separada. Cada uno de los valores de los colores se configuran de forma independiente. Esto le permite obtener más de 16,5 millones de combinaciones de colores.

// int int int int

http://www.fibidi.com/?p=321 red = 6; green = 5; blue = 3; i,j,k;

//

void setup() { Serial.begin(9600); pinMode(red, OUTPUT); pinMode(green, OUTPUT); pinMode(blue, OUTPUT); } void loop() { int sensorred = analogRead(A0); i = map(sensorred, 0, 1023, 0, 255); Serial.print(i); Serial.print(" "); analogWrite(red, i); int sensorgreen = analogRead(A1); j = map(sensorgreen, 0, 1023, 0, 255); Serial.print(j); Serial.print(" "); analogWrite(green, j); int sensorblue = analogRead(A2); k = map(sensorblue, 0, 1023, 0, 255); Serial.print(k); Serial.print(" "); analogWrite(blue, k);

delay(1); Serial.println(); }

Fritzing = spiffy

Yo estaba teniendo un montón de problemas para visualizar lo que tengo que hacer para conseguir algunas de las cosas que quiero crear todo improvisado correctamente en un circuito , por no hablar de saber qué partes de lo que necesito. Encontré este sitio impresionante , Fritzing.org que realmente ayuda ! Puede descargar el programa, el cual le permite hacer diseños que buscan Super Slick visualmente ( o como un esquema , si eso es más fácil para usted !) . Así que al menos ahora puedo hacer circuitos de aspecto profesional para demostrar que ustedes , y espero que alguien me puede decir si van a hacer teh asplode robut o no! Para conseguir la caída de ella , hice un esquema para un pequeño circuito que me puse a jugar con un LED RGB . Esquema después de la protuberancia ! Sketch Muestra Arduino Este bosquejo pulsa los canales RGB en un LED a un ritmo diferente . Botón 1 : te permite alternar los canales dentro y fuera , y el Botón 2 cambia la intensidad máxima permitida. Para hacer esto es necesario : Arduino Uno Una placa 1 RGB LED 10 cables Cinco 330 ohm resistencias Dos pulsadores El diseño de su tablero como esto ( gracias Fritzing ) ! Aquí está el código para el pequeño circuito.

/* This lets you mess with an RGB LED and Two buttons. It is curently set up so that the brightness fluctuates

Cycles through the colors of a RGB LED Based on RGB_LED_Color_Fade_Cycle.pde Written for SparkFun Arduino Inventor's Kit CIRC-RGB */ /* VERBOSE? Prints to serial monitor */ const boolean VERBOSE = true; // LED leads connected to PWM pins const int RED_LED_PIN = 3; const int GREEN_LED_PIN = 5; const int BLUE_LED_PIN = 6; /* Button pins */ const int BTN_1_PIN = 8; const int BTN_2_PIN = 9;

/* Thresholds for intensity of LED */ const int MAX_INTENSITY = 255; //Full brightness const int MIN_INTENSITY = 5; //Minimum Brightness // Used to store the current intensity level of the individual LEDs int redIntensity = 0; int greenIntensity = 0; int blueIntensity = 0; // All of those levels are controlled by this one. See the loop code. int intensity = 255; //Channel on/off state - 0 = off, 1 = on int redState = 1; int greenState = 1; int blueState = 1; //The bounced the master intensity between MIN_ and MAX_INTENSITY int dir = -1; //This variables represents time - +1 each tick. Used for Trig. int t = 0; // Length of time we spend showing each color const int DISPLAY_TIME = 50; // In milliseconds /* States to toggle thru RGB on/off */ int states[6][3] = {{0,0,1}, {0,1,0}, {0,1,1}, {1,0,0}, {1,0,1}, {1,1,1}}; int currState = 5; //Set to the one above, all colors on. int numStates =6; //Used to cause the button to make an action once each time it is pressed. boolean btn1_DOWN = false; //SETUP THE BUTTONS void setup() { Serial.begin(9600); pinMode(BTN_1_PIN, INPUT); pinMode(BTN_2_PIN, INPUT); } void loop() { int btn1 = digitalRead(BTN_1_PIN); int btn2 = digitalRead(BTN_2_PIN); /*Change active colors Only do this once each time the button is pressed and released */ if(btn1 == LOW) { btn1_DOWN = true;

} else if(btn1 == HIGH){ if(btn1_DOWN == true) { btn1_DOWN = false; currState++; if (currState == numStates) { currState = 0; } redState = states[currState][0]; greenState = states[currState][1]; blueState = states[currState][2]; if (VERBOSE) { Serial.print("::: redState "); Serial.print(redState); Serial.print(" greenState "); Serial.print(greenState); Serial.print(" blueState "); Serial.print(blueState); Serial.println(); } } } /*CHANGE INTENSITY Changed continuously while button is pressed. */ if(btn2 == LOW) { if (dir == -1) { intensity-=5; if(intensity = MAX_INTENSITY) { intensity = MAX_INTENSITY; dir = -1; } } if (VERBOSE) { Serial.print(" INTENSITY::"); Serial.print(intensity); Serial.println(); } } //Use trig functions to make the channels pulse at different rates. redIntensity = abs(int(intensity * sin(t*0.01)));

greenIntensity = abs(int(intensity * cos(t*0.02))); blueIntensity = abs(int(intensity * sin(t*0.03))); analogWrite(RED_LED_PIN, redIntensity * redState); analogWrite(GREEN_LED_PIN, greenIntensity * greenState); analogWrite(BLUE_LED_PIN, blueIntensity * blueState); delay(DISPLAY_TIME); t++; }

.

Led RGB I

En esta nueva práctica vamos a trabajar con un led RGB, mediante el cual vamos a explicar las entradas digitales. Además, jugaremos con él en programación, introduciendo las estructuras de control if y for Existen dos tipos de led RGB: los de dos patas que llevan integrado un circuito de control y los de cuatro patas. Nosotros trabajaremos con los últimos. Estos led RGB son, en realidad, como si hubiéramos metido tres leds en una misma cápsula, uno rojo (red), otro verde (green) y otro azul (blue). Poseen 4 patillas, pudiendo tener 3 ánodos para los tres colores (rojo, azul y verde) y un cátodo común, o bien, 3 cátodos para cada color y un ánodo común, usaremos los primeros. Combinando los tres colores (adicción), en sus diferentes luminosidades, podemos obtener una

gran gama de colores. Para variar la luminosidad hay que jugar con la intensidad, pero eso lo veremos en la siguiente práctica. De momento nos conformaremos con los tres colores primarios y sus combinaciones.

Vamos a programar la siguiente sucesión: 1.

Rojo – Verde – Azul x5

2.

(R+V=Amarillo) – (R+A=Magenta) – (V+A=Cían) x5

3.

(R+V+A=Blanco)

/* Led RGB Realiza una sucesión de color mediante un led RGB. */ int ledRojo = 9; //Declaro pin para cátodo del rojo int ledVerde = 10; //Declaro pin para cátodo del verde int ledAzul = 11; //Declaro pin para cátodo del azul void setup() { pinMode(ledRojo, OUTPUT); //Configuro el pin 9 como salida pinMode(ledVerde, OUTPUT); //Configuro el pin 10 como salida pinMode(ledAzul, OUTPUT); //Configuro el pin 11 como salida } void loop() { for(int i=0;i