Go Down

Topic: 8 bit binary code to text (Read 1 time) previous topic - next topic

spina

Feb 14, 2017, 04:40 am Last Edit: Feb 14, 2017, 04:45 am by spina
https://youtu.be/AnaV-HP8rkw

Text to binary code:

Code: [Select]
void setup() {
  Serial.begin(9600);         // open serial port at 9600 baud
}

void loop() {
  if(Serial.available()) {    // if anything on port
 
    byte c = Serial.read();   // read one character
    for(int i=0; i<8; i++) { 
      Serial.print(c%2);      // print the least significant bit
      delay(100);
      c /= 2;                 // move to next significant bit
    }
  }

}



I want to reverse this process. Help.

Binaty code in digital input  to text ?


Code: [Select]
???

2trillion

I think what you want to do is define the character instead of reading a character value.  So delete the "byte c"line and in the header add a char definition.

Code: [Select]
char c = 'text';

uxomm

#2
Feb 26, 2017, 01:57 am Last Edit: Feb 26, 2017, 02:12 am by uxomm
Code: [Select]
char c = 'text';
This will not work.
In C/C++ "char" is just *one single* value.
You can use a character array, but you have to use double quotes instead of single ones and curly brackets.
Code: [Select]
char c[] = {"text"};
This array has 5 values (not 4) because it has a termination character (null character: 0x00) at the end.
The termination character is added automatically in this case.
For more detailed information see: https://www.arduino.cc/en/Reference/String

And to the initial question: I am sorry, I don't understand what the thread opener wants to do.
Always decouple electronic circuitry.

2trillion

Yeah I didn't understand exactly what the OP wanted to do too.  You can use char(x) to turn a number into a character.  So if byte() defines a number then that should be able to be used in char() to make a character.  However, I might be totally off.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy