This library is used for student's experiment. Chiba Institute of Technology

Dependencies:   QEI SoftwarePWM

Fork of adrobo by yasuo hayashibara

Sound.cpp

Committer:
yasuohayashibara
Date:
2020-04-20
Revision:
1:45772cb4e01c
Parent:
0:4508c5b68135

File content as of revision 1:45772cb4e01c:

#include "Sound.h"

Sound::Sound(PinName pin)
  : pwm(pin)
{
    this->write(0);
    pwm.Enable(0, 1000000);
}

void Sound::write(float frequency)
{
    frequency_ = frequency;
    if (frequency_ != 0){
        int us = (int)(1000000.0f / frequency_);
        pwm.Disable();
        pwm.Enable(us/2, us);
    } else {
        pwm.Disable();
    }
}

float Sound::read()
{
  return frequency_;
}