Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int pinLED = 13;
- 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;
- 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
- }
- void loop()
- {
- String red="";
- String green="";
- String blue="";
- int rojo=0;
- int verde =0;
- int azul =0;
- if (Serial.available()>0)
- {
- while(Serial.available())
- {
- char c = Serial.read();
- if((c!='\r') && (c!='\n'))
- {
- cadena+=c;
- }
- delay(20);
- }
- if(cadena.charAt(0)=='r')
- {
- for(int i=1:i<cadena.length();i++)
- {
- red+=cadena.charAt(i);
- }
- }
- else if(cadena.charAt(0)=='v')
- {
- for(int i=1:i<cadena.length();i++)
- {
- green+=cadena.charAt(i);
- }
- }
- else if(cadena.charAt(0)==='a')
- {
- for(int i=1:i<cadena.length();i++)
- {
- blue+=cadena.charAt(i);
- }
- }
- rojo = red.toInt();
- verde = green.toInt();
- azul = blue.toInt();
- color(rojo, verde, azul); // apagado
- delay(10);
- }
- }
- // funcion para generar colores
- void color (int rojo, int verde, int azul)
- {
- analogWrite(pinLedR, rojo);
- analogWrite(pinLedV, verde);
- analogWrite(pinLedA, azul);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement