I used LabVIEW for my serial transmission where it sends decimal data to proteus, but my proteus does only receive 1 character at a time in terms of decimal data.
void loop()
{ // put your main code here, to run repeatedly:
// reply only when you receive data:
if (Serial.available() >0) {
// read the incoming byte:
incomingByte = Serial.read ();
incomingByte -= 48;
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
if(incomingByte == 0b1000000)
{
digitalWrite(Led1, HIGH);
Serial.println("Led is On");
Serial.println("\n");
}
if(incomingByte == 0b0000010)
{
digitalWrite(Led2, HIGH);
Serial.println("Led is On");
Serial.println("\n");
}
Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
@zdiin, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with nor for advise on your project. See About the Installation & Troubleshooting category.
Note that this is not a Proteus forum. Also note that nothing beats the real Arduino
0b1000000 is 64 not 1, this is important because looking at your code it seems you recieve a number in a string format then subtract 48 to get the binary value and I dont believe you intended to send a value of 112 (which is the ascii value of lower case p) from labview.
Another thing worth a mention is that a byte is 8 bits and not 7 as in your notation, this is not affecting your logic because you can get away without the leading zeros but I say this incase you are not aware of how many bits there are in a byte.
Unless things are going to get a lot more complex than the code you have shown us it may be easier for you to type the number as a decimal, the two following lines mean the same thing.
It sends Boolean data to control its individual LEDs, the boolean output has been connected to array where it become binary and i used conversion to decimal after that
Thanks for mentioning the position of the bit in binary, i totally forgot about that, i have been trying to figure it out how it could read the binary from the incoming data from labview
My current problem on the coding is that, how can i save the incoming data full bit instead of 1 bit at a time and then change the incoming data to binary for the LED condition
Incoming data is sent 8 bits or 1 byte at a time. It arrives in binary there is no need to convert it, it arrives exactly as it is sent. However, you need to know what the sender meant by the bytes it is sending. At the end of the day all bytes are, are patterns of bits, these can be interpreted in an almost infinite number of ways. For example they could be simple numbers between 0 and 255, or signed numbers according to the ons'e complement or the two's complement system. They could represent alpha numeric symbols from a keyboard using the well known ASCII mapping of bit patterns to symbols. They can even represent a mores code pattern, in fact anything you can dream up.
Output from Labview as it has been transferred through serial port is a string, for example 32
I could possible change that binary and send it as a string
Input received by proteus is 3 and 2 instead 32
Can anyone help with saving that in term of binary or sort of binary pattern (if string of binary data is used)
You have been asked to fix your original post, and you have not done so. If your ignore that request, maybe you will ignore any help that is offered here?