// Bonus points constructor, which allows the user to connect a custom function // to a bumper. RedBotBumper::RedBotBumper(int pin, void(*functionPointer)(void)) { setPinChangeInterrupt(pin, WHISKER); pinMode(pin, INPUT_PULLUP); setBumpFunction(pin, functionPointer); _pin = pin; // set local variable for the pin }
// Bonus points constructor, which allows the user to connect a custom function // to a bumper. RedBotBumper::RedBotBumper(int pin, void(*functionPointer)(void)) { setPinChangeInterrupt(pin, WHISKER); pinMode(pin, INPUT_PULLUP); setBumpFunction(pin, functionPointer); }
// Standard class constructor, assumes that you want to halt the motors on a // bump. A more skilled programmer than I could figure out the error message // I get if I try to use the brake() function that's a part of the RedBotMotor // class; I worked around it by making a globally available one. RedBotBumper::RedBotBumper(int pin) { setPinChangeInterrupt(pin, WHISKER); pinMode(pin, INPUT_PULLUP); setBumpFunction(pin, &brake); }