Stap 6: Arduino verbinding/Programing.
Het programma is gekoppeld.
declarando variabelen
int emisor = 12;
int receptor = A0;
char in; int valor;
int modulo;
int bytes [8] = {0,0,0,0,0,0,0,0};
int i = 0; int T = 20; int t = 10;
int de dato; int EH = 0; int ED = 1;
int SYN = 0;
int valoresbase [8] = {1,2,4,8,16,32,64,128};
char mensaje [100]; int j = 0;
VALOR in-48; = Conversie de Caracter een decimaal
in = valor + 0x30; It converts decimaal een caracter
void setup)
{pinMode(emisor,OUTPUT);
digitalWrite(emisor,HIGH);
Serial.begin(9600);
while(SYN==0) {Serial.println("Sincronizando...");
while(eh==0) {dato=digitalRead(receptor);
if(dato==High) {Serial.println ("Seguiremosrecibiendo senal...");
EH = 1; ED = 0; } }
arreglo para almacenamiento de datos
Serial.println ("Presione 1 para iniciar comunicacion");
while(ed==0) {if(Serial.available() > 0) {in=Serial.read();
if(in=='1') {ED = 1; SYN = 1; }} dato=digitalRead(receptor);
if(dato==low) {Serial.println ("Se perdio la senal..."); EH = 0; ED = 1; SYN = 0;
} } }
Serial.println ("Inicia ComunicaciÛn"); Serial.println(); }
void loop)
{if(Serial.available() > 0)
{//Transmite dato in=Serial.read();
Serial.Print ("Enviar:");
Serial.println(in);
VALOR = in;
Conversie de Caracter een decimale Serial.print("Valor Decimal:");
Serial.println(Valor);
Serial.Print ("Valor Binary:");
Inicia conversie de decimale een binary
while(Valor>1)
{modulo = valor %2; bytes [i] = modulo; i ++;
Valor = valor/2; } if(valor==1)
{modulo = valor %2; bytes [i] = modulo;}
if(Valor==0) {bytes [i] = 0;} voor (ik = 7; ik > -1; ik--)
{Serial.print(bytes[i]);
Imprime numero binary
}
Serial.println();
Inicia transmissie de dato
Serial.Print ("Transmitiendo:")
; digitalWrite(emisor,LOW);
delay(t); voor (ik = 0; ik < 8; i ++)
{Serial.print(bytes[i]);
if(bytes[i]==0)
{digitalWrite(emisor,LOW);
} if(bytes[i]==1)
{digitalWrite(emisor,HIGH);
} delay(T);
}
Reset variabelen
digitalWrite(emisor,HIGH);
voor (ik = 0; ik < 8; i ++) {bytes [i] = 0;
} Ik = 0; Serial.println();
Serial.println();
delay(100); }
dato=digitalRead(receptor);
if(dato==low)
{//Recibe dato Serial.print ("Seguiremosrecibiendo:");
delay(T);
Inicia Recepcion de dato
voor (ik = 0; ik < 8; i ++)
{dato=digitalRead(receptor);
if(dato==High)
{bytes [i] = 1; Serial.Print('1');
}
if(dato==low) {bytes [i] = 0;
Serial.Print('0');
}
delay(T);
}
while(eh==0)
{
Termina Recepcion de dato
dato=digitalRead(receptor);
if(dato==High) {EH = 1;}}
Serial.println();
Serial.Print ("Valor Binary:");
voor (ik = 7; ik > -1; ik--
{Serial.print(bytes[i]);}
Serial.println();
Conversie de binary een decimaal
Valor = 0; voor (ik = 0; ik < 8; i ++)
{if(bytes[i]==1)
{valor = valor + valoresbase [i];} }
Serial.Print ("Valor decimaal:");
Serial.println(Valor);
in = valor + 0x30;
It converts decimaal een caracter
Serial.Print ("Se envio:");
Serial.println(in);
Als (in ==' voor (j = 0; j < 100; j ++)
{mensaje [j] = "";} j = 0; }
else {mensaje [j] =; j ++; Serial.println();
Serial.println("mensaje:"); voor (ik = 0; i