com.google.android.things.contrib.driver.pwmspeaker.Speaker Java Examples

The following examples show how to use com.google.android.things.contrib.driver.pwmspeaker.Speaker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpeakerActivity.java    From drivers-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        mSpeaker = new Speaker(BoardDefaults.getPwmPin());
        mSpeaker.stop(); // in case the PWM pin was enabled already
    } catch (IOException e) {
        Log.e(TAG, "Error initializing speaker");
        return; // don't initilize the handler
    }

    mHandlerThread = new HandlerThread("pwm-playback");
    mHandlerThread.start();
    mHandler = new Handler(mHandlerThread.getLooper());
    mHandler.post(mPlaybackRunnable);
}
 
Example #2
Source File: PianoActivity.java    From android-things-distributed-piano with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        speaker = new Speaker(BoardDefaults.getPwmPin());
        presenter = new PianoPresenter(this, (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE),
                getString(R.string.service_id), getPackageName());
    } catch (IOException e) {
        throw new IllegalArgumentException("Piezo can't be opened, lets end this here.");
    }
}
 
Example #3
Source File: RainbowHatInstrumentationTest.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Opens PWM buzzer and sends values to it.
 */
@Test
public void testPwmBuzzer() throws IOException {
    Speaker speaker = RainbowHat.openPiezo();
    speaker.play(200);
    speaker.stop();
    speaker.close();
}
 
Example #4
Source File: RainbowHat.java    From contrib-drivers with Apache License 2.0 4 votes vote down vote up
public static Speaker openPiezo() throws IOException {
    return new Speaker(BOARD.getPiezoPwm());
}