ENTREGA

Dependencies:   mbed

Fork of 01-04EntregaPrimerCorte by ferney alberto beltran molina

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers analogo.cpp Source File

analogo.cpp

00001 #include "mover.h"
00002 #include "main.h"
00003 #include "mbed.h"
00004 #include "math.h"
00005 AnalogIn analog_value(A0);
00006 //AnalogIn analog_y(A1);
00007 
00008 
00009 Serial pc1(USBTX, USBRX);
00010 DigitalOut led1(PB_8);
00011 void m_analogo(uint8_t motores, uint8_t posicion)
00012 {
00013     float meas_r;
00014     float meas_v;
00015     
00016     pc1.printf("\nAnalogIn example\n");
00017 
00018     while(1) {
00019 
00020         meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
00021         meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range
00022         
00023         // Display values
00024         pc1.printf("measure = %f = %f mV\n", meas_r, meas_v);
00025 
00026         // LED is ON is the value is below 1V
00027         if (meas_v < 1000) {
00028             led1= 1; // LED ON
00029             mover_adelante(); 
00030         } 
00031         if(meas_v > 2000){
00032           mover_atras();
00033             }
00034         else {
00035             led1= 0; // LED OFF
00036         }
00037 
00038         wait(1); // 1 second
00039     }
00040 }
00041 void  mover_adelante(){
00042      mover_frenteanalog();
00043      }
00044  void  mover_atras(){
00045     mover_atrasanalog();
00046      }