Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- BertieHarte
- Date:
- 2019-07-29
- Revision:
- 2:b88fecb5232c
- Parent:
- 1:760c5b759868
File content as of revision 2:b88fecb5232c:
//lab 2_4_1_Modified.
// Modify the code so that the for loop parameters are variables which can be initialised at the start of the program
// and modified in the while loop to produce a different sound second time around.
#include "mbed.h"
DigitalIn fire(p14); // centre pin of joystick.
PwmOut spkr(p26); // speaker output
int b = 1; // base time for pwm output. this will be divided by the value of 'r'. This will increment up by 10 after first loop.
int r = 100; // base value for the increment of float 'i'. This is used in the PWM calculation, and will increment up by 10 after the first loop.
int c = 0; //counter on loop.
int main() {
while(c < 2) { // only repeat loop twice (c will increment after each pass), once c !<2 the program will stop.
for (float i=2000.0; i<10000; i+=r) { // increment i by 'r' each loop if the value at the start of the loop is less than 1000
spkr.period((b)/i); // base time/i
spkr=0.5;
wait(0.1);
}
spkr=0.0;
b += 10;// increment b by +10
r += 10; // increment r by +10
c +=1;// increment count by one.
printf("Count is %i \n\r", c); // only for display purposes during testing.
while(!fire) {}
}
}