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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:da458f1db225
- Parent:
- 0:c8b89a6e4c0e
- Child:
- 2:77448d13dd0d
diff -r c8b89a6e4c0e -r da458f1db225 main.cpp
--- a/main.cpp Thu Oct 18 15:57:42 2018 +0000
+++ b/main.cpp Fri Oct 19 04:09:07 2018 +0000
@@ -1,26 +1,53 @@
#include "mbed.h"
+AnalogIn analog_value(A5);
+BusOut vu_leds = (PA_3,PA_2,PA_10,PB_3,PB_5,PB_4,PB_10,PB_8);
+BusOut digit1=(PA_9,PC_7,PB_6,PA_7);
+BusOut digit2=(PB_0,PA_4,PA_1,PA_0);
+DigitalIn user(USER_BUTTON);
+DigitalOut led(LED1);
+long map(long x, long in_min, long in_max, long out_min, long out_max)
+{
+ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
+double power(int x,int y)
+{
+ int z=x;
+ while(y>0) {
+ z=z*x;
+ y--;
+ }return z;
+}
+void display_vu(unsigned int x)
+{
+ int out=power(2,x)-1;
+ vu_leds=out;
+}
+void display_digits(int x)
+{
+ digit1=x/10;
+ digit2=x%10;
-AnalogIn analog_value(A0);
-
-DigitalOut led(LED1);
-
+}
int main()
{
- float meas_r;
- float meas_v;
-
+ float adc1;
+ int volt1;
+ int volum;
+ bool mode;
while(1) {
- meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
- meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range
-
- // LED is ON when the value is above 2V
- if (meas_v > 2000) {
- led = 1; // LED ON
+ adc1 = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
+ volt1 = map(adc1,0,1.0,0,33); // Converts value in the 0V-3.3V range
+ volum = map(adc1,0,1.0,0,8);
+ if(mode) {
+ display_vu(volum);
} else {
- led = 0; // LED OFF
+ display_digits(volt1);
}
-
+ if(user) {
+ mode=!mode;
+ while(user);
+ }
wait(0.2); // 200 millisecond
}
}