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.
Fork of slider_tone_v1 by
Revision 3:ee81131ce456, committed 2015-04-27
- Comitter:
- vbharam
- Date:
- Mon Apr 27 23:45:01 2015 +0000
- Parent:
- 2:7f347d6a6422
- Commit message:
- Patle code
Changed in this revision
slider_tone_v1.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/slider_tone_v1.cpp Sat Feb 14 23:03:06 2015 +0000 +++ b/slider_tone_v1.cpp Mon Apr 27 23:45:01 2015 +0000 @@ -24,9 +24,12 @@ TSISensor tsiScaling; // Capacitive sensor/slider +AnalogIn analogRand(PTB3); PwmOut led(LED_RED); DigitalOut outPin(PTC9); //J1-16 PwmOut soundOut(PTA13); +Serial pc(USBTX, USBRX); + // Global scalars char lcdData[LCDLEN]; @@ -54,7 +57,6 @@ } void lightAdjust( float scaling) { // Control brightness of LED float tempDutyFactor; - tempDutyFactor = 1.0 - scaling; //LED is a sinking connection // anode is held at 5V led.write(tempDutyFactor); //sdjusting duty factor @@ -63,11 +65,15 @@ int main(){ int tempInt; float tempValue; + float analogValue; + float mx = 0; + float mn = 1; + float previousDelta = 0; + float delta = 0; + tonePeriod = 1.0/toneFreq; soundOut.period(tonePeriod); - - led.write(CHANNELON); outPin.write(CHANNELOFF); tempInt = (int)toneFreq; @@ -77,10 +83,27 @@ while (true) { tempValue = tsiScaling.readPercentage(); - if(tempValue > 0) { + for (int i = 0; i < 1000; ++i) { + analogValue = analogRand.read(); + //mn = mn > analogValue ? analogValue : mn; +// mx = mx < analogValue ? analogValue : mx; + if (analogValue > mx){ + mx = analogValue; + } + if (analogValue < mn){ + mn = analogValue; + } + + } + delta = mx - mn; + + pc.printf("%f %f %f %f\n", analogValue, mx, mn, delta); + wait_ms(DATATIME); + if(previousDelta != delta) { soundOut.write(TONEON); // set duty factor to 505 - toneAdjust( tempValue); - lightAdjust(tempValue); + toneAdjust( analogValue); + lightAdjust(analogValue); + previousDelta = delta; } else { soundOut.write(TONEOFF); // set dutyfactor to 0% LCDMessNoDwell("SOFF");