How do i use bitread correctly?

i try to use bitread in my program but it doesn't work, It just gives a bunch of 0-oes

here is my program:

for (int i = 0; i < 14; i++) {
int b = bitRead(addr, i);
if (b==0) {
digitalWrite(ADDR, LOW);
} else {
digitalWrite(ADDR, HIGH);
}
digitalWrite(CLK, HIGH);
delay(1);
digitalWrite(CLK, LOW);
}

Your code is incomplete.

Please remember to use code tags when posting code

1 Like

From: bitRead() - Arduino Reference

Description

Reads a bit of a number.

Syntax

bitRead(x, n)

Parameters

x: the number from which to read.
n: which bit to read, starting at 0 for the least-significant (rightmost) bit.

Returns

The value of the bit (0 or 1).

If you are trying to read the Ith bit from 0-14 of the variable ADDR, then this is correct, but I think you might be trying to read the word at ADDR instead, correct?

1 Like

I realized that i only had 0 as addres in the rest of my code

Just like this

xEventGroupWaitBits (eg, evtParseMQTT, pdTRUE, pdTRUE, portMAX_DELAY ); //
    xSemaphoreTake( sema_mqttOK, portMAX_DELAY );
    mqttOK = 0;

does not mean much to you, this

does not mean much to me.

Post all your code, please.

Glad you figured it out. :smiley:
Post more of your code next time and someone else can probably help you spot issues like that.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.