0 -- > 1 ; 1 --> 0 [led to photodiode] SOLVED USING HARDWARE DEVICE PORTA NAND

Hy everybody,
I am communicating trough Serial.port,
I would like to invert the received Signal (LED tx, photodiode rx) in order to obtain the original one.
I want to send char, such as “<” "> " “;”

Serial.print('<',BIN);

I obtain 111100

how can I have 000011 to be able to read again ‘<’ in the other side?
there are some predefine function to do it?

Subtraction: 0b11111111 - 0b00111100 = 0b11000011
You can look up the characters at www.asciitable.com also. 0011 1100 = 0x3C

You need to try explaining the problem in a different way as it does not make much sense to me.
The code you posted just displays the ASCII character ‘<’ in binary as a string of characters.
Look here and you will see < is 60 decimal and convert this to binary you get 111100

Posted by Riva

  • Today at 12:35 pm Quote

You need to try explaining the problem in a different way as it does not make much sense to me.
The code you posted just displays the ASCII character ‘<’ in binary as a string of characters.
Look here and you will see < is 60 decimal and convert this to binary you get 111100

and what I will like to have is 000011, so when I read it with photodiode I see 111100. That It is what I want to send :slight_smile:

Posted by CrossRoads

  • Today at 12:33 pm Quote

Subtraction: 0b11111111 - 0b00111100 = 0b11000011
You can look up the characters at www.asciitable.com also. 0011 1100 = 0x3C

I didnt think about it!!! I guess it is the simplest way to reach what I wanted. I always forget K.I.S.S. :frowning:

I don't quite understand the problem, but maybe the bitwise negation operator can help you as well:

byte a = 01010101b;
byte b = ~a;
Serial.println (b, BIN);

This will yield 10101010.

Posted by SukkoPera

  • Today at 12:59 pm Quote

I don't quite understand the problem, but maybe the bitwise negation operator can help you as well:

In the case my type in an int
for example

int analog = analogRead(A0);
Serial.print(analog,BIN);

but I want to send analog in BIN but kind of 11111111 - (analog,BIN)
I need to change the base of analog before I can Serial.print it.
bit Wise I can use after it is already a binary.

It is possible to do this kind of operation?

Serial.println(bitRead(!analog , 1));

or here I am doing NOT to an INT?

or I know that with itoa it is possibile to convert the interger in binary base but it stays a CHAR.

Giulialiuyi:
or here I am doing NOT to an INT?

I think you intended to use the bitwise NOT, "~".

But like everyone else, I still have no idea what you are trying to do.

Send value from Serial port to be read from a photodiodo. So I need to invert them.
What it is not clear?
photodiodo gives max value when ite doesnt see anything so when I am sending 0 it gives me 1.
and photodiodo gives min value when it see max value so when I am sending 1 it gives me back 0.

I want to map this result.

and analogRead gives result in int.

Maybe there is a esiaer way? then bitWise not. bcs to apply it i need to convert in binary firts.

Well, I think my answer above says it all, just keep in mind that what you need is BITWISE negation (~), not LOGICAL negation (!). It will work fine for 16 bits, or any number of bits anyway.

with bitWise it gives me back _-256

:o :confused: :cry:

Symbols like ">" are arbitrary. So inverting them makes NO sense. It would be like turning the word "true" upside down to represent false. When you encode with arbitrary symbols, the meaning is preserved as long as the receiving decoding function is the inverse of the sending encode function.

@aarg: I think he/she needs this function exactly to make the encoding and decoding functions symmetric.

@Giulialiuyi: what are you transmitting and what are you receiving? Maybe you need to cast the received byte to a char?

SukkoPera:
@aarg: I think he/she needs this function exactly to make the encoding and decoding functions symmetric.

I can't imagine ANY circumstance in which logically inverted ASCII characters would be of any use. Can you?

Well, if the character bits get inverted by the transmission method, you will need to invert them again to get back what you transmitted... At least that's what I seem to understand from all this nonsense!

SukkoPera:
Well, if the character bits get inverted by the transmission method, you will need to invert them again to get back what you transmitted... At least that's what I seem to understand from all this nonsense!

...and what would be the advantage to that?

If you send 0 you don't want to receive 1, I guess!

I realize that the original posters first language may not be English. So I am not going to criticize the language. But I think the problem still has not been explained well enough that anybody here could help.

This is what I seem to understand:

  • The OP has a transmission medium made by a led and a photoresistor.
  • To transmit a 0, the led remains dark, to transmit a 1, the led lights up.
  • Without considering how the transmission is clocked, it seems that with how things are wired up on the receiver's side, when the led is lit, a 0 is received, when the led is off a 1 is received. This is probably because of photoresistors having high impendance in the dark, and low impedance in bright light conditions.
  • Thus the received signal must either be bitwise inverted or the receiver circuit rewired to make that unnecessary (Maybe moving the photoresistor to the other side of the voltage divider).

If the serial is sent by means of light hardware, inverting the data bits won't help because the idle state, and start and stop bits can not be inverted in software.

Well, maybe it's a "serial" protocol the OP has designed him/herself or found somewhere, with fixed number of bits and timing. Who knows...