Lab Day 2, Experiment 2.4: Speaker

Dependencies:   mbed

Committer:
t00209054
Date:
Sat Aug 01 08:42:49 2020 +0000
Revision:
0:08b089f9884b
Lab day 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
t00209054 0:08b089f9884b 1 #include "mbed.h"
t00209054 0:08b089f9884b 2 DigitalIn fire(p14);
t00209054 0:08b089f9884b 3 PwmOut spkr(p26);
t00209054 0:08b089f9884b 4 AnalogIn pot1(p19);
t00209054 0:08b089f9884b 5 float start = 2000.0, end = 10000.0, step = 100;
t00209054 0:08b089f9884b 6
t00209054 0:08b089f9884b 7 int main()
t00209054 0:08b089f9884b 8 {
t00209054 0:08b089f9884b 9 while (1) {
t00209054 0:08b089f9884b 10 for (float i=start; i<end; i+=step) {
t00209054 0:08b089f9884b 11 spkr.period(1.0/i);
t00209054 0:08b089f9884b 12 spkr=0.5;
t00209054 0:08b089f9884b 13 wait(0.1);
t00209054 0:08b089f9884b 14 }
t00209054 0:08b089f9884b 15 spkr=0.0;
t00209054 0:08b089f9884b 16 start = 3000.0;
t00209054 0:08b089f9884b 17 end = 5000.0;
t00209054 0:08b089f9884b 18 while(pot1.read() < 0.5) {} // this uses the pot to control the program
t00209054 0:08b089f9884b 19 }
t00209054 0:08b089f9884b 20 }