Advertisement
franciscominajas

PROCESSING IMAGE_ARDUINO

Oct 12th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //inicializacion de bibliotecas
  2. #include <SoftwareSerial.h>
  3. #include <stdlib.h>
  4. //declaracion de constantes
  5. int pinLedR = 11;  // pin Rojo del led RGB
  6. int pinLedV = 10;  // pin Verde del led RGB
  7. int pinLedA = 9;   // pin Azul del led RGB
  8. float valor;
  9. String cadena="";
  10. //inicializacion de los puertos y velocidad de operacion
  11. void setup()
  12. {
  13.    Serial.begin(9600);
  14.    pinMode(pinLedR, OUTPUT);    // pone el pinLedR como output
  15.    pinMode(pinLedV, OUTPUT);    // pone el pinLedV como output
  16.    pinMode(pinLedA, OUTPUT);    // pone el pinLedA como output
  17. }
  18. // funcion para generar colores
  19. void color (int rojo, int verde, int azul)
  20. {
  21.   analogWrite(pinLedR, rojo);
  22.   analogWrite(pinLedV, verde);
  23.   analogWrite(pinLedA, azul);
  24. }
  25. void loop()
  26. {
  27.   //variables para obtener los colores
  28.   int rojo=0;
  29.   int verde =0;
  30.   int azul =0;
  31.   if (Serial.available() > 0)
  32.   {
  33.       while (Serial.available())
  34.       {
  35.           rojo = Serial.read();
  36.       verde = Serial.read();
  37.       azul = Serial.read();
  38.       //envio de respuesta a processing
  39.       String hola = String(String(rojo)+" "+String(verde)+" "+String(azul));
  40.       Serial.println(hola);
  41.       //impresion de valores en RGB
  42.       color(rojo,verde,azul);
  43.       delay(50);
  44.       }
  45.    }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement