voltimetro con 12 leds

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
DanielOlarte
Date:
Sat Aug 20 14:52:54 2016 +0000
Commit message:
Voltimetro con 12 leds

Changed in this revision

ADC.cpp Show annotated file Show diff for this revision Revisions of this file
ADC.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r dbf284e4050a ADC.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC.cpp	Sat Aug 20 14:52:54 2016 +0000
@@ -0,0 +1,142 @@
+#include "ADC.h"
+
+
+void adc::configout(PinName led1,PinName led2,PinName led3,PinName led4,PinName led5,PinName led6,PinName led7,PinName led8,PinName led9,PinName led10,PinName led11, PinName led12)
+{
+    _led1=led1;
+    _led2=led2;
+    _led3=led3;
+    _led4=led4;
+    _led5=led5;
+    _led6=led6;
+    _led7=led7;
+    _led8=led8;
+    _led9=led9;
+    _led10=led10;
+    _led11=led11;
+    _led12=led12;
+}
+
+
+int adc::adcx(double ent)
+{
+
+    int cont;
+    double meast;
+    BusOut BusB(_led1,_led2,_led3,_led4,_led5,_led6,_led7,_led8);
+    BusOut BusA(_led9,_led10,_led11,_led12);
+    ent = ent * 0.000050354;
+    meast=ent;
+
+    if(meast>0&&meast<=0.275) {
+        cont=1;
+    }
+    if(meast>0.275&&meast<=0.55) {
+        cont=2;
+    }
+    if(meast>0.55&&meast<=0.825) {
+        cont=3;
+    }
+    if(meast>0.825&&meast<=1.1) {
+        cont=4;
+    }
+    if(meast>1.1&&meast<=1.375) {
+        cont=5;
+    }
+    if(meast>01.375&&meast<=1.65) {
+        cont=6;
+    }
+    if(meast>1.65&&meast<=1.925) {
+        cont=7;
+    }
+    if(meast>1.925&&meast<=2.2) {
+        cont=8;
+    }
+    if(meast>2.2&&meast<=2.475) {
+        cont=9;
+    }
+    if(meast>2.475&&meast<=2.75) {
+        cont=10;
+    }
+    if(meast>2.75&&meast<=3.025) {
+        cont=11;
+    }
+    if(meast>3.025&&meast<=3.3) {
+        cont=12;
+    }
+
+
+    switch(cont) {
+
+        case 0: {
+            BusA=0x00;
+            BusB=0x00;
+            break;
+        }
+        case 1: {
+            BusA=0x00;
+            BusB=0x01;
+            break;
+        }
+        case 2: {
+            BusA=0x00;
+            BusB=0x03;
+            break;
+        }
+        case 3: {
+            BusA=0x00;
+            BusB=0x07;
+            break;
+        }
+        case 4: {
+            BusA=0x00;
+            BusB=0x0f;
+            break;
+        }
+        case 5: {
+            BusA=0x00;
+            BusB=0x1f;
+            break;
+        }
+        case 6: {
+            BusA=0x00;
+            BusB=0x3f;
+            break;
+        }
+        case 7: {
+            BusA=0x00;
+            BusB=0x7f;
+            break;
+        }
+        case 8: {
+            BusA=0x00;
+            BusB=0xff;
+            break;
+        }
+        case 9: {
+            BusA=0x01;
+            BusB=0xff;
+            break;
+        }
+        case 10: {
+            BusA=0x03;
+            BusB=0xff;
+            break;
+        }
+        case 11: {
+            BusA=0x07;
+            BusB=0xff;
+            break;
+        }
+        case 12: {
+            BusA=0x0f;
+            BusB=0xff;
+            break;
+        }
+    }
+    
+    return BusB;
+}
+
+
+
diff -r 000000000000 -r dbf284e4050a ADC.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC.h	Sat Aug 20 14:52:54 2016 +0000
@@ -0,0 +1,30 @@
+#ifndef ADC
+#define ADC_h
+#include "mbed.h"
+
+class adc
+
+{
+public:
+
+
+    void configout(PinName led1,PinName led2,PinName led3,PinName led4,PinName led5,PinName led6,PinName led7,PinName led8,PinName led9,PinName led10,PinName led11, PinName led12);
+    int adcx(double meas);
+    
+private:
+
+    PinName _led1;
+    PinName _led2;
+    PinName _led3;
+    PinName _led4;
+    PinName _led5;
+    PinName _led6;
+    PinName _led7;
+    PinName _led8;
+    PinName _led9;
+    PinName _led10;
+    PinName _led11;
+    PinName _led12;
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r dbf284e4050a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Aug 20 14:52:54 2016 +0000
@@ -0,0 +1,21 @@
+#include "ADC.h"
+
+Serial pc(USBTX, USBRX);
+AnalogIn lec(A0);
+
+int main()
+{
+    int imp;
+    double meas;
+    adc lab2;
+    lab2.configout(D2,D3,D4,D5,D6,D7,D8,D9,D10,D11,D12,D13);
+
+    while(1) {
+
+        meas = lec.read_u16();
+        imp=lab2.adcx(meas);
+        pc.printf("%i\n\r",imp);
+        wait(0.2);
+    }
+
+}
\ No newline at end of file
diff -r 000000000000 -r dbf284e4050a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Aug 20 14:52:54 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b0220dba8be7
\ No newline at end of file