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:
- 4:964ee3cf1a43
- Parent:
- 3:3395362f87b8
--- a/main.cpp Fri Oct 19 04:22:41 2018 +0000
+++ b/main.cpp Fri Oct 19 14:28:34 2018 +0000
@@ -1,31 +1,14 @@
#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);
+AnalogIn adc1(A5);
+BusOut vu_leds(PA_10,PB_3,PB_5,PB_4,PB_10,PA_8,PA_9,PC_7);
+BusOut digit2(PA_0,PA_1,PA_4,PB_0);
+BusOut digit1(PC_3,PC_2,PH_1,PH_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)
-{
- if (y>0) {
- int z=x;
- } else {
- return 1
- }
- while(y>0) {
- z=z*x;
- y--;
- }
- return z;
-}
+Serial pc(USBTX, USBRX);
void display_vu(unsigned int x)
{
- int out=power(2,x)-1;
- vu_leds=out;
+ vu_leds=0xff>>(8-x);
}
void display_digits(int x)
{
@@ -35,24 +18,29 @@
}
int main()
{
- float adc1;
+
int volt1;
int volum;
bool mode;
while(1) {
-
- 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-33V range
- volum = map(adc1,0,1.0,0,8);
- if(mode) {
+ float read =adc1.read();
+ pc.printf("%f\t",read);
+ volt1 = read*33;
+ volum = read*8;
+ pc.printf("%d\t%d\n",volt1,volum);
+ if(!mode) {
display_vu(volum);
+ digit2=0;
+ digit1=0;
} else {
display_digits(volt1);
+ vu_leds=0;
}
- if(user) {
+ if(!user) {
mode=!mode;
- while(user);
+ while(!user);
}
wait(0.2); // 200 millisecond
+ led = !led;
}
}