void countStep() {
if (PINC & B0100000) target1--; // pin A5 represents direction
else target1++;
}
and this
void encoder() { // pulse and direction, direct port reading to save cycles
if (PINB & 0b00000001) encoderPos++; // digital pin 8 if(digitalRead(encodPinB1)==HIGH)
count ++;
else encoderPos--; // if(digitalRead(encodPinB1)==LOW) count --;
God invented digitalRead(), digitalWrite(), pinMode(). Use them. e.g.
if(digitalRead(encodPinB1)==HIGH)
Yes, you can write bare-metal SAMD21 code. But the Arduino functions work pretty well on the SAMD21.
I use SAMD21 registers when writing to a TFT because there are millions of instructions to just clear the screen.
Other hardware like LCD, Encoder, Temp Sensor, ... only need a few digitalxxxx() statements. So speed is not important.