Sin wave generation class using D/A converter(LPC1768)
Dependents: agic_touch_panel_v3
Diff: Sinwave.cpp
- Revision:
- 0:e934e95962bd
diff -r 000000000000 -r e934e95962bd Sinwave.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sinwave.cpp Tue Jun 24 04:44:48 2014 +0000 @@ -0,0 +1,24 @@ +#include "mbed.h" +#include "Sinwave.h" + +Sinwave::Sinwave(PinName DAport,float amplitude,float frequency):DAport_(DAport){ + int i; + float pi = 3.1415; + cycle_ = 1.0/(frequency*10.0); + for(i = 0;i < 10;i++){ + outputs_[i] = amplitude*0.5 * (float)sin(2*pi*frequency*cycle_*i) + 0.5; + } +} +void Sinwave::update(){ + static int i = 0; + DAport_.write(outputs_[i]); + i++; + i = i % 10; +} +void Sinwave::start(){ + output_int_.attach(this,&Sinwave::update,cycle_); +} +void Sinwave::stop(){ + output_int_.detach(); +} + \ No newline at end of file