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.
Diff: main.cpp
- Revision:
- 1:760c5b759868
- Parent:
- 0:5742b01051e5
- Child:
- 2:b88fecb5232c
diff -r 5742b01051e5 -r 760c5b759868 main.cpp
--- a/main.cpp Sun Jul 28 09:44:44 2019 +0000
+++ b/main.cpp Mon Jul 29 08:40:09 2019 +0000
@@ -1,12 +1,20 @@
#include "mbed.h"
-
+//modified version of initial program.
+// declare varibles for 'i+=' (rate of change) and spkr.period calculation (pitch).
DigitalIn fire(p14); // centre pin of joystick.
PwmOut spkr(p26); // speaker output
+// add analog inputs for pot 1 & 2
+AnalogIn pot1(p19);
+AnalogIn pot2(p20);
int main() {
while(1) {
- for (float i=2000.0; i<10000; i+=100) { // increment i by 200 each loop if the value at teh start of the loo is less than 1000
- spkr.period(1.0/i);
+ float roc = (pot1*100); // read pot 1 and * by 100.
+ printf("pot1 = %.0f \n\r", (roc)); // used for display during testing.
+ float spk = (pot2*10); // read pot 1 and * by 10.
+ printf("pot2 = %.0f \n\r", (spk)); // display for testing
+ 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
+ spkr.period((spk)/i); // base time is taken for the pot 2 calculation.
spkr=0.5;
wait(0.1);
}