Is there a simpler / cleaner way to do line 31?
I want to preserve the upper nybble of PORTB and insert ONLY the LOWER nybble of hSteps[].
PORTB = (hSteps[cntr & 0x7] & 0x0F) | (PORTB & 0xF0);
/* pin 8 to pin 1 on ULN2003, pin 16 to pink, coilA
9 to pin 2, 15 yellow, coilC
10 to pin 3, 14 orange, coilB
11 to pin 4, 13 blue, coilD
Type a number in top of serial monitor for steps to go,
-2 billion (CCW) to 2 billion (CW) & press [ENTER].
*/
uint32_t tStart, tEnd = 916UL;
const byte fSteps [8] = {0x01, 0x02, 0x04, 0x08, 0x01, 0x02, 0x04, 0x08};
const byte hSteps [8] = {0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09};
byte cntr = 0;
long stg; // steps to go
void setup()
{
Serial.begin(9600);
DDRB = 0x0F; // set pins 8,9,10,11 to OUTPUT
}
void loop()
{
if (Serial.available() > 0)
{
stg = Serial.parseInt();
Serial.println(stg);
}
if (stg != 0)
{
tStart = micros();
while(micros() - tStart < tEnd);
PORTB = (hSteps[cntr & 0x7] & 0x0F) | (PORTB & 0xF0);
// sets direction, adds to or subtracts from stg
// depending on direction
stg < 0 ? cntr-- : cntr++;
stg < 0 ? stg++ : stg--;
}
}
TNX All.