click buttons to change motor direction
void setup()
{
DDRD = 0b01101100; //pin 2, 3, 5, 6 output
PORTD = 0b01000100; //set initial motor directions
PCICR = 0b00000001; //interrupt group 1
PCMSK0 = 0b00000011; //pin 7 interrupt
sei();
}
void loop()
{
}
ISR(PCINT0_vect){
//if interrupt on pin 8(PB0), toggle pin 2, 3
if ( (PINB&(1<<0)) ){
PORTD ^= 0b00001100;
}
//if interrupt on pin 9(PB1), toggle pin 5, 6
if ( (PINB&(1<<1)) ){
PORTD ^= 0b01100000;
}
}
reference:
port register
H bridge driver
No comments:
Post a Comment