Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //inicializacion de bibliotecas
- #include <SoftwareSerial.h>
- #include <stdlib.h>
- //declaracion de constantes
- int pinLedR = 11; // pin Rojo del led RGB
- int pinLedV = 10; // pin Verde del led RGB
- int pinLedA = 9; // pin Azul del led RGB
- float valor;
- String cadena="";
- //inicializacion de los puertos y velocidad de operacion
- void setup()
- {
- Serial.begin(9600);
- pinMode(pinLedR, OUTPUT); // pone el pinLedR como output
- pinMode(pinLedV, OUTPUT); // pone el pinLedV como output
- pinMode(pinLedA, OUTPUT); // pone el pinLedA como output
- }
- // funcion para generar colores
- void color (int rojo, int verde, int azul)
- {
- analogWrite(pinLedR, rojo);
- analogWrite(pinLedV, verde);
- analogWrite(pinLedA, azul);
- }
- void loop()
- {
- //variables para obtener los colores
- int rojo=0;
- int verde =0;
- int azul =0;
- if (Serial.available() > 0)
- {
- while (Serial.available())
- {
- rojo = Serial.read();
- verde = Serial.read();
- azul = Serial.read();
- //envio de respuesta a processing
- String hola = String(String(rojo)+" "+String(verde)+" "+String(azul));
- Serial.println(hola);
- //impresion de valores en RGB
- color(rojo,verde,azul);
- delay(50);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement