hello dear
I’m receiving from a capture light sensor module, an binaire code.
i whould to convert them to code ascii CARACTAIRE
THIS’S THE CODE OF RECEVIER :
for (int i = 0; i < 8; i++) {
if (analogRead(ldr) >= 800)
{ arr = 1; }
_ else{ arr = 0; }_ _ Serial.print(arr*); Serial.print(’\r’); i++; delay(200);
not familiar LI-FI protocol but if all you are doing is using it as a media for tx/rx a serial (ie RS-232) byte then how are you determining the START or a byte ie
if no data is tx is “analogRead(ldr) >= 800” for example?
for serial tx for example, the line is HIGH when idle and LOW for 1 bit period to mark the start or a byte.
from there then all you need to do bit shift each read bit into a byte (char type) and print it!
something like this snippet:
void rx_byte(void)
{
uint8_t data_val;
uint8_t cnt;
uint8_t err;
/* pin as input pull up */
RX_PIN_INPUT_PULLUP();
while(1)
{
data_val = 0U;
err = 0U;
/* while pin is high */
while(analogRead(ldr) >= 800);
/* 1.5 bit delay */
delay(DELAY_US_1_5_BIT);
/* get byte */
for(cnt = 0U ; cnt < 8U ; cnt++)
{
data_val >>= 1;
if(analogRead(ldr) >= 800) data_val |= 0x80;
/* 1 bit delay */
delay(DELAY_US_1_0_BIT);
}
/* stop bit error low */
if(analogRead(ldr) < 800)
{
err = 1;
}
}
bear in mind that ‘analogRead’ take some time to process meaning to would need to ‘tune’ all the delay timings to compensate