How do I read from a data.h file?

Dear Forum;

This to me seems like it should be a simple thing and easy to implement, but I think I am having a bad day and really cant find a solution. It really is entry level stuff I expect.

I have a data.h file I wish to include in the build code, the file includes a series of hex values to be used in an LED animation.

I am unsure right now how to extract this data to be then be translated into LED outputs. On searching forums I find answers for real time reading of files, via USB etc, AFTER the code has been built. For me however, I want the data read as part of the build process.

Should I be using the read() command?, how do I point to the right position within the file?

Can anyone point me in the right direction please. Many thanks in advance

JS

The first step is adding the line:

#include "data.h"

to the file that you want to give access to that file.

As for how to read the hex values from data.h, there’s no way to say without looking at data.h. Please post it using code tags(</> button on the toolbar) or attach it if it’s too long for the forum to allow it in the post.

"How do I read the data..." implies that at run time, you expect to read something from the file. That is NOT how header files work. The preprocessor reads the file at compile time. You don't have to do anything.

The header file contains code, just like the sketch.

Hello;

Yes, I have learn a little more now and now understand include files are basically extra lines in the code, thanks PaulS.

I am still having problems.

I have am using a utility that can make data files based on animation files, of the format (truncated) below, which stores them in HEX.

const uint8_t PROGMEM anim[] = { 0X37, 0X58, 0X3B, 0X38, 0XFF, 0XFF, 0X37, 0X31, 0X37, 0X58, * 0X44, 0X38, 0XFF, 0XFC, 0X3A, 0X2A, 0X37, 0X58, 0X48, 0X3D, 0XFF, 0XFC,* * 0X3E, 0X28, 0X36, 0X58, 0X00, 0X50, 0X42, 0X01, 0XFF, 0XFC, 0X00, 0X41,* * 0X22, 0X37, 0X58, 0X58, 0X46, 0XFF, 0XFA, 0X45, 0X1F, 0X36, 0X58, 0X00,* * 0X62, 0X4D, 0X02, 0XFF, 0XF7, 0X00, 0X4D, 0X1B, 0X36, 0X58, 0X00, 0X6B,* * 0X58, 0X03, 0XFF, 0XF4, 0X00, 0X53, 0X18, 0X37, 0X58, 0X77, 0X62, 0XFF,* * 0XED }*

I am struggling now to know how to extract this data once its stored, particularly since it is stored in HEX. I have looked at the PROGREM pages and unsure how. Ideally I want to serial.write the values so that I can check the values for debug and that its actually loading the file correctly.

I know I may have deviated off the original topic slightly, any thoughts welcome whilst I continue to try things out myself.

JS

I am struggling now to know how to extract this data once its stored, particularly since it is stored in HEX.

It is NOT stored in HEX. It is stored in memory in binary. But, that has NO affect on how you access the data.

Ideally I want to serial.write the values so that I can check the values for debug and that its actually loading the file correctly.

What are you sending the values to? The Serial Monitor application will not understand your sending it binary data.

I have looked at the PROGREM pages and unsure how.

There are pgm_read_XXX functions for several different data types. Use the one that is appropriate for your data type (byte).