I am reading in a single byte over TWI. Each bit stands for something. I want to be able to read that byte into a data structure, then be able to reference each bit. I had thought of something like this
Serial.print(mykyes.key1); // would print a zero or one.
But the above doesn't work. I think I an misunderstanding how struct works. Anyone have any thoughts on what would be the simplest way to get the value of each bit?
tempalte has got a lot of the right parts, just not all together.
The packed bitfield structure is correct. That will let you access the 8 bits of the byte individually. But if you want to assign a byte into it, then you either need to put it inside a union or do some typecasting.
For whatever reason, it is not the habit of Arduino programmers or the avr-gcc people to use bit structures. They tend to shift and mask. At a first glance, the object code is about the same so it is a matter of preference. (Personally, I like bit structs for fixed structures, but I don't code that way here.)