The iPod controller that I submitted for the mbed challenge
Dependencies: mbed Motordriver PID
Diff: user_interface/buzzer.h
- Revision:
- 0:371773dd3dd1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/user_interface/buzzer.h Wed May 04 15:41:13 2011 +0000 @@ -0,0 +1,29 @@ +#ifndef BUZZER_H +#define BUZZER_H +#include "MCP23017.h" + +class buzzer { + MCP23017& _intf; + Timeout t; + void stop() { + char tmp = _intf.read(PORT_B); + tmp &= ~BUZZ; + _intf.write(PORT_B, tmp); + } +public: + buzzer(MCP23017& intf): _intf(intf) { + intf.direction(PORT_B, INPUTS);// rot enc input + intf.configurePullUps(PORT_B, INPUTS); + } + ~buzzer() { + t.detach(); + stop(); + } + void buzz(int ms) { + char tmp = _intf.read(PORT_B); + tmp |= BUZZ; + _intf.write(PORT_B, tmp); + t.attach_us(this, &buzzer::stop, ms*1000); + } +}; +#endif \ No newline at end of file