Problem in bit reading with pgm_read_byte()

I need to work with bit, and so i choice pgm style.

Why this code is not working as expected?

#include <avr/pgmspace.h> //for pgm_read_byte

const prog_uint8_t wcode[9] = {   // store in program memory to save RAM
			B10010000,
			B11100000,
			B01000010,
			B11010000,
			B00000000,
			B00000000,
			B01100100,
			B00000101,
			B10100000  //last 4 bit is not used
		};
void setup() {                
 Serial.begin(9600); 
}
void loop() {
 for (byte x=0; x<9; ++x) {
    byte data = pgm_read_byte (&wcode[x]);   // fetch data from program memory
        for (byte y=0; y<8; ++y) {
            if (data & (1<<y)) {
                Serial.print("1");
            } else {
	       Serial.print("0");
            }
        }
        Serial.println("");
               
    }
    Serial.println("");
   Serial.println("");
    delay(15*1000);
}

This code return this bit sequence

00100000
10000100
01101001
00010011
00001100
10001011
10100000
10000010
11101111

You are missing the PROGMEM declaration:

const prog_uint8_t PROGMEM wcode[9] = {

Thank you. I’m sorry :blush:

Another question i have some function have a PROGMEM const like this

void sendCode2() {
	const prog_uint8_t PROGMEM wcode[9] = {   // store in program memory to save RAM
			B10000000,
			B11100000,
			B01000010,
			B11010000,
			B00000000,
			B00000000,
			B01100100,
			B00000101,
			B10100000  //last 4 bit is not used
		};
	useCode(&wcode);
}
void useCode(){
for (byte x=0; x<9; ++x) {
    byte data = pgm_read_byte (&wcode[x]);   // fetch data from program memory
        for (byte y=0; y<8; ++y) 
            //do some stuff with code
            if (data & (1<<y)) {
                Serial.print("1");
            } else {
	       Serial.print("0");
            }
        }               
    }
}

As you can seeuseCode function hasn’t any param. What the correct method for passing “wcode” variable from sendCode() to useCode() ? I need to use pointers? How?

Sorry, is correct to use this code? (note the pointers)

void sendCode2() {
	const prog_uint8_t PROGMEM wcode[9] = {   // store in program memory to save RAM
			B10000000,
			B11100000,
			B01000010,
			B11010000,
			B00000000,
			B00000000,
			B01100100,
			B00000101,
			B10100000  //last 4 bit is not used
		};
	useCode(&wcode);
}
void useCode(uint8_t *wcode){
for (byte x=0; x<9; ++x) {
    byte data = pgm_read_byte (&wcode[x]);   // fetch data from program memory
        for (byte y=0; y<8; ++y) 
            //do some stuff with code
            if (data & (1<<y)) {
                Serial.print("1");
            } else {
	       Serial.print("0");
            }
        }               
    }
}