geekhack
geekhack Projects => Making Stuff Together! => Topic started by: confusedtapeworm on Thu, 05 April 2018, 18:05:51
-
void matrix_init_kb(void) {
DDRB &= ~(1 << 1); // Rotary input A -> Pin B1
//PORTB |= (1 << 1); // Pull-up pin A
DDRF &= ~(1 << 7); // Rotary input B -> Pin F7
//PORTF |= (1 << 7); // Pull-up pin B
}
void matrix_scan_kb(void) {
rotaryA = (PINB & (1 << 1)); //read inputs from both pins
rotaryB = (PINF & (1 << 7));
if ((PinALast == 0) && (rotaryA == 1)){ //compare current and previous states of pin A
if (rotaryB == 0){
register_code(KC_VOLU); // do ****
unregister_code(KC_VOLU);
}
else {
register_code(KC_VOLD);
unregister_code(KC_VOLD);
}
}
PinALast = rotaryA;
}
This is the code I have. The exact same code runs perfectly fine on Arduino Micro when I use digitalRead or whatever instead of the direct bit manipulation stuff. I'm probably missing something but I can't tell what. Are my bit manipulations wrong? Am I trying to use forbidden pins? What's the deal here?
Appreciate all the help.
-
If you want to compare with 0 and 1 you need to shift right the results of the rotaryA by 1, and the rotaryB by 6 if I'm not mistaken.
Because you are reading PORTF7 you dont get a 0 or a 1, you get 0b10000000 or 0b00000000, or in decimal 128 or 0.
And PORTB1 gives you 0b00000010 or 0b00000000, or in decimal 2 or 0.