SlideShare a Scribd company logo
1 of 2
const uint8_t red = 9;
const uint8_t green = 10;
const uint8_t blue = 11;
uint8_t digito = 0;
uint8_t contComa = 0;
uint8_t valor = 0;
uint8_t vR = 0, vG = 0, vB = 0;
void setup() {
Serial.begin(9600);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
// Serial.print("R: ");
// Serial.println(vR);
// Serial.print("G: ");
// Serial.println(vG);
// Serial.print("B: ");
// Serial.println(vB);
analogWrite(red, 255);
analogWrite(green, 255);
analogWrite(blue, 255);
}
void loop() {
if (Serial.available() > 0) {
procesarDato(Serial.read());
}
}
void procesarDato (int c) { ///
------------------------------------------------------------------
if (isdigit (c)) {
switch (contComa) {
case 0:
vR = numero(c) + vR;
break;
case 1:
vG = numero(c) + vG;
break;
case 2:
vB = numero(c) + vB;
break;
}
} else {
if (isPunct(c)) {
contComa = contComa + 1;
digito = 0;
} else {
if (isControl(c)) {
encenderLed();
}
}
}
}
// end of procesarDato ///
------------------------------------------------------------------
int numero(const int c) {
int dato;
dato = c - 48;
switch (digito) {
case 0:
valor = dato;
digito = 1;
break;
case 1:
valor = (dato * 10) + valor;
digito = 2;
break;
case 2:
valor = (dato * 100) + valor;
digito = 0;
break;
}
return valor;
}
//-------------------------------------
void encenderLed() {
analogWrite(red, map(vR, 0, 255, 255, 0));
analogWrite(green, map(vG, 0, 255, 255, 0));
analogWrite(blue, map(vB, 0, 255, 255, 0));
// Serial.print("R: ");
// Serial.println(vR);
// Serial.print("G: ");
// Serial.println(vG);
// Serial.print("B: ");
// Serial.println(vB);
valor = 0;
digito = 0;
contComa = 0;
vR = 0;
vG = 0;
vB = 0;
}

More Related Content

What's hot (8)

Temps reel
Temps reelTemps reel
Temps reel
 
ProcessingとArduinoの連携
ProcessingとArduinoの連携ProcessingとArduinoの連携
ProcessingとArduinoの連携
 
MFC Combo box
MFC Combo boxMFC Combo box
MFC Combo box
 
MFC ELC
MFC ELCMFC ELC
MFC ELC
 
contoh program avr
contoh program avrcontoh program avr
contoh program avr
 
latihan SAP
latihan SAPlatihan SAP
latihan SAP
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Programacion
ProgramacionProgramacion
Programacion
 

More from Fredy Serna

Carro a control remoto por Zigbee IEE802.15.4
Carro a control remoto por  Zigbee IEE802.15.4Carro a control remoto por  Zigbee IEE802.15.4
Carro a control remoto por Zigbee IEE802.15.4Fredy Serna
 
Carro a control remoto Zigbee IEE802.15.4
Carro a control remoto Zigbee IEE802.15.4Carro a control remoto Zigbee IEE802.15.4
Carro a control remoto Zigbee IEE802.15.4Fredy Serna
 
Documentación PG
Documentación PGDocumentación PG
Documentación PGFredy Serna
 
Guía sensores 1
Guía sensores 1Guía sensores 1
Guía sensores 1Fredy Serna
 
Proyecto 3 Circuitos
Proyecto 3 CircuitosProyecto 3 Circuitos
Proyecto 3 CircuitosFredy Serna
 
Proyecto 2, Circuitos.
Proyecto 2, Circuitos.Proyecto 2, Circuitos.
Proyecto 2, Circuitos.Fredy Serna
 
Compuertas Lógicas + Códigos
Compuertas Lógicas + CódigosCompuertas Lógicas + Códigos
Compuertas Lógicas + CódigosFredy Serna
 

More from Fredy Serna (10)

Carro a control remoto por Zigbee IEE802.15.4
Carro a control remoto por  Zigbee IEE802.15.4Carro a control remoto por  Zigbee IEE802.15.4
Carro a control remoto por Zigbee IEE802.15.4
 
Carro a control remoto Zigbee IEE802.15.4
Carro a control remoto Zigbee IEE802.15.4Carro a control remoto Zigbee IEE802.15.4
Carro a control remoto Zigbee IEE802.15.4
 
Documentación PG
Documentación PGDocumentación PG
Documentación PG
 
Guía sensores 1
Guía sensores 1Guía sensores 1
Guía sensores 1
 
Proyecto 3 Circuitos
Proyecto 3 CircuitosProyecto 3 Circuitos
Proyecto 3 Circuitos
 
P proyecto 3
P proyecto 3P proyecto 3
P proyecto 3
 
Proyecto 2, Circuitos.
Proyecto 2, Circuitos.Proyecto 2, Circuitos.
Proyecto 2, Circuitos.
 
Proyecto 2
Proyecto 2Proyecto 2
Proyecto 2
 
Compuertas Lógicas + Códigos
Compuertas Lógicas + CódigosCompuertas Lógicas + Códigos
Compuertas Lógicas + Códigos
 
Informe P1
Informe P1Informe P1
Informe P1
 

Código Arduino

  • 1. const uint8_t red = 9; const uint8_t green = 10; const uint8_t blue = 11; uint8_t digito = 0; uint8_t contComa = 0; uint8_t valor = 0; uint8_t vR = 0, vG = 0, vB = 0; void setup() { Serial.begin(9600); pinMode(red, OUTPUT); pinMode(green, OUTPUT); pinMode(blue, OUTPUT); // Serial.print("R: "); // Serial.println(vR); // Serial.print("G: "); // Serial.println(vG); // Serial.print("B: "); // Serial.println(vB); analogWrite(red, 255); analogWrite(green, 255); analogWrite(blue, 255); } void loop() { if (Serial.available() > 0) { procesarDato(Serial.read()); } } void procesarDato (int c) { /// ------------------------------------------------------------------ if (isdigit (c)) { switch (contComa) { case 0: vR = numero(c) + vR; break; case 1: vG = numero(c) + vG; break; case 2: vB = numero(c) + vB; break; } } else { if (isPunct(c)) { contComa = contComa + 1; digito = 0; } else { if (isControl(c)) { encenderLed(); } } } } // end of procesarDato /// ------------------------------------------------------------------ int numero(const int c) { int dato; dato = c - 48;
  • 2. switch (digito) { case 0: valor = dato; digito = 1; break; case 1: valor = (dato * 10) + valor; digito = 2; break; case 2: valor = (dato * 100) + valor; digito = 0; break; } return valor; } //------------------------------------- void encenderLed() { analogWrite(red, map(vR, 0, 255, 255, 0)); analogWrite(green, map(vG, 0, 255, 255, 0)); analogWrite(blue, map(vB, 0, 255, 255, 0)); // Serial.print("R: "); // Serial.println(vR); // Serial.print("G: "); // Serial.println(vG); // Serial.print("B: "); // Serial.println(vB); valor = 0; digito = 0; contComa = 0; vR = 0; vG = 0; vB = 0; }