int inByte = 0;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect
}
establishContact(); // wait for incoming data
} /* setup */
void loop() {
// Contoh: ABC -> NOP -> ABC
if (Serial.available() > 0) // if you have data input
{
inByte = Serial.read(); // read one byte of input
// A to M get converted to N to Z
if (inByte >= 'A' && inByte <= 'M')
{
inByte += 13;
} /* if upper case A-M */
// N to Z get converted to A to M
else if (inByte >= 'N' && inByte <= 'Z')
{
inByte -= 13;
} /* if upper case N-Z */
// Lower case a to m get converted to n to z
else if (inByte >= 'a' && inByte <= 'm')
{
inByte += 13;
} /* if lower case a-m */
// Lower case n to z get converted to a to m
else if (inByte >= 'n' && inByte <= 'z')
{
inByte -= 13;
} /* if lower case n-z */
Serial.write(inByte); // write the encrypted character back
}
}
void establishContact()
{
// write 'A' repeatedly until you receive data from the host
while (Serial.available() <= 0)
{
Serial.print('W'); // write 'A' to the host
delay(1000); // this delay is optional
} // while Serial.available() <= 0
Serial.println();
} // establishContact()
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect
}
establishContact(); // wait for incoming data
} /* setup */
void loop() {
// Contoh: ABC -> NOP -> ABC
if (Serial.available() > 0) // if you have data input
{
inByte = Serial.read(); // read one byte of input
// A to M get converted to N to Z
if (inByte >= 'A' && inByte <= 'M')
{
inByte += 13;
} /* if upper case A-M */
// N to Z get converted to A to M
else if (inByte >= 'N' && inByte <= 'Z')
{
inByte -= 13;
} /* if upper case N-Z */
// Lower case a to m get converted to n to z
else if (inByte >= 'a' && inByte <= 'm')
{
inByte += 13;
} /* if lower case a-m */
// Lower case n to z get converted to a to m
else if (inByte >= 'n' && inByte <= 'z')
{
inByte -= 13;
} /* if lower case n-z */
Serial.write(inByte); // write the encrypted character back
}
}
void establishContact()
{
// write 'A' repeatedly until you receive data from the host
while (Serial.available() <= 0)
{
Serial.print('W'); // write 'A' to the host
delay(1000); // this delay is optional
} // while Serial.available() <= 0
Serial.println();
} // establishContact()
cek di serial monitor dan coba tuliskan sesuatu disana dan klik enter
Salam Arduino Indonesia
Tidak ada komentar:
Posting Komentar