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.
Revision 1:e4d5bf9c63f5, committed 2015-04-28
- Comitter:
- rahulpatle101
- Date:
- Tue Apr 28 02:01:54 2015 +0000
- Parent:
- 0:fe8967d28c75
- Commit message:
- try2
Changed in this revision
| read_microphont.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/read_microphont.cpp Mon Apr 27 23:56:50 2015 +0000
+++ b/read_microphont.cpp Tue Apr 28 02:01:54 2015 +0000
@@ -1,68 +1,73 @@
#include "mbed.h"
#include "SLCD.h"
#include "TSISensor.h"
-
-
+#include <algorithm> // std::max
+
+
#define CHANNELON 0
#define CHANNELOFF 1
#define LCDLEN 10
#define DATATIME 0.1
//LCD messages
-
-
-
+
+
+
// Operating parameters
-#define SIDETONE 700.0
+#define SIDETONE 700.0
#define TONEMIN 200.0
#define TONEINT 800.00 // So tone max is 1000
#define TONEON 0.50
#define TONEOFF 0.0
#define SPEEDAST 0
#define TONEAST 1
-
+
SLCD slcd; //define LCD display
-
+
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];
-
+
float tonePeriod;
float toneFreq = SIDETONE;
-
-
-
-void LCDMessNoDwell(char *lMess){
- slcd.Home();
- slcd.clear();
- slcd.printf(lMess);
-}
-
-void toneAdjust( float scaling) {
+
+
+
+void LCDMessNoDwell(char *lMess)
+{
+ slcd.Home();
+ slcd.clear();
+ slcd.printf(lMess);
+}
+
+void toneAdjust( float scaling)
+{
int tempInt;
-
+
toneFreq = TONEMIN + scaling * TONEINT;
- tonePeriod = 1.0/toneFreq;
+ tonePeriod = 1.0/toneFreq;
soundOut.period(tonePeriod); // adusting period
tempInt = (int)toneFreq;
sprintf (lcdData,"%4d",tempInt);
LCDMessNoDwell(lcdData);
return;
}
-void lightAdjust( float scaling) { // Control brightness of LED
+void lightAdjust( float scaling) // Control brightness of LED
+{
float tempDutyFactor;
- tempDutyFactor = 1.0 - scaling; //LED is a sinking connection
- // anode is held at 5V
+ tempDutyFactor = 1.0 - scaling; //LED is a sinking connection
+ // anode is held at 5V
led.write(tempDutyFactor); //sdjusting duty factor
return;
}
-int main(){
+int main()
+{
int tempInt;
float tempValue;
float analogValue;
@@ -70,44 +75,48 @@
float mn = 1;
float previousDelta = 0;
float delta = 0;
-
- tonePeriod = 1.0/toneFreq;
+
+ tonePeriod = 1.0/toneFreq;
soundOut.period(tonePeriod);
-
+
led.write(CHANNELON);
outPin.write(CHANNELOFF);
tempInt = (int)toneFreq;
sprintf (lcdData,"%4d",tempInt);
LCDMessNoDwell(lcdData);
- wait(DATATIME);
+ wait(DATATIME);
while (true) {
-
+
tempValue = tsiScaling.readPercentage();
- for (int i = 0; i < 1000; ++i) {
+ for (int i = 0; i < 100; ++i) {
analogValue = analogRand.read();
- //mn = mn > analogValue ? analogValue : mn;
+ mx = max(mx, analogValue);
+ mn = min(mn, analogValue);
+
+
+ //mn = mn > analogValue ? analogValue : mn;
// mx = mx < analogValue ? analogValue : mx;
- if (analogValue > mx){
- mx = analogValue;
- }
- if (analogValue < mn){
- mn = analogValue;
- }
-
+ //if (analogValue > mx){
+// mx = analogValue;
+// }
+// if (analogValue < mn){
+// mn = analogValue;
+// }
+
}
delta = mx - mn;
-
- pc.printf("%f %f %f %f\n", analogValue, mx, mn, delta);
+
+ pc.printf("%f %f %f %f \n", analogValue, mn, mx, delta);
wait_ms(DATATIME);
if(previousDelta != delta) {
soundOut.write(TONEON); // set duty factor to 505
toneAdjust( analogValue);
lightAdjust(analogValue);
previousDelta = delta;
- } else {
+ } else {
soundOut.write(TONEOFF); // set dutyfactor to 0%
LCDMessNoDwell("SOFF");
- }
- wait(DATATIME);
+ }
+ wait(DATATIME);
} // while forever
}// end main
\ No newline at end of file