Bertie Harte / Mbed 2 deprecated Intrumentation_lab_2_4_1_Speakermodified

Dependencies:   mbed

Committer:
BertieHarte
Date:
Mon Jul 29 08:40:09 2019 +0000
Revision:
1:760c5b759868
Parent:
0:5742b01051e5
Child:
2:b88fecb5232c
Version 2 modified to use variables from pots.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BertieHarte 0:5742b01051e5 1 #include "mbed.h"
BertieHarte 1:760c5b759868 2 //modified version of initial program.
BertieHarte 1:760c5b759868 3 // declare varibles for 'i+=' (rate of change) and spkr.period calculation (pitch).
BertieHarte 0:5742b01051e5 4 DigitalIn fire(p14); // centre pin of joystick.
BertieHarte 0:5742b01051e5 5 PwmOut spkr(p26); // speaker output
BertieHarte 1:760c5b759868 6 // add analog inputs for pot 1 & 2
BertieHarte 1:760c5b759868 7 AnalogIn pot1(p19);
BertieHarte 1:760c5b759868 8 AnalogIn pot2(p20);
BertieHarte 0:5742b01051e5 9
BertieHarte 0:5742b01051e5 10 int main() {
BertieHarte 0:5742b01051e5 11 while(1) {
BertieHarte 1:760c5b759868 12 float roc = (pot1*100); // read pot 1 and * by 100.
BertieHarte 1:760c5b759868 13 printf("pot1 = %.0f \n\r", (roc)); // used for display during testing.
BertieHarte 1:760c5b759868 14 float spk = (pot2*10); // read pot 1 and * by 10.
BertieHarte 1:760c5b759868 15 printf("pot2 = %.0f \n\r", (spk)); // display for testing
BertieHarte 1:760c5b759868 16 for (float i=2000.0; i<10000; i+=(roc)) { // increment i by the calculated roc each loop if the value at the start of the loop is less than 1000
BertieHarte 1:760c5b759868 17 spkr.period((spk)/i); // base time is taken for the pot 2 calculation.
BertieHarte 0:5742b01051e5 18 spkr=0.5;
BertieHarte 0:5742b01051e5 19 wait(0.1);
BertieHarte 0:5742b01051e5 20 }
BertieHarte 0:5742b01051e5 21 spkr=0.0;
BertieHarte 0:5742b01051e5 22 while(!fire) {}
BertieHarte 0:5742b01051e5 23 }
BertieHarte 0:5742b01051e5 24 }