Lab Day 2, Experiment 2.4: Speaker

Dependencies:   mbed

main.cpp

Committer:
t00209054
Date:
2020-08-01
Revision:
0:08b089f9884b

File content as of revision 0:08b089f9884b:

#include "mbed.h" 
DigitalIn fire(p14); 
PwmOut spkr(p26); 
AnalogIn pot1(p19);
float start = 2000.0, end = 10000.0, step = 100;
 
int main() 
{ 
        while (1) { 
            for (float i=start; i<end; i+=step) { 
            spkr.period(1.0/i); 
            spkr=0.5; 
            wait(0.1); 
        } 
        spkr=0.0; 
        start = 3000.0;
        end = 5000.0;
        while(pot1.read() < 0.5) {} // this uses the pot to control the program 
    } 
}