I'm currently trying to control a stepper motor using simple full steps. This means that I'm currently outputting a sequence of values like this:
1000
0100
0010
0001
I thought an easy way to do this was just take my 4-bit value and after each step, perform a rotate right operation. "Code" obviously isn't following any kind of syntax, it's simply there to illustrate my thoughts:
step = 1000;
//Looping
Motor_Out(step)
//Rotate my step variable right by 1 bit
Rotate_Right(step, 1)
My problem is that there obviously isn't any 4-bit simple data types that I can use for this, and if I use an 8-bit unsigned int I will eventually rotate the 1 off to the MSB, which means the 4-bit value I'm actually interested in, will turn into 0000 for a few steps.
I've read that you can use structs and bit-fields to solve this, but the majority of things I read from this is telling me that it's a very bad idea.