program 1 driver
Dependencies: mbed motorController2
main.cpp@0:1d2060237094, 2016-10-31 (annotated)
- Committer:
- BalB
- Date:
- Mon Oct 31 17:49:32 2016 +0000
- Revision:
- 0:1d2060237094
- Child:
- 1:3370c513ff5c
first try reading analogs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
BalB | 0:1d2060237094 | 1 | #include "mbed.h" |
BalB | 0:1d2060237094 | 2 | |
BalB | 0:1d2060237094 | 3 | // |
BalB | 0:1d2060237094 | 4 | // By BalB |
BalB | 0:1d2060237094 | 5 | // |
BalB | 0:1d2060237094 | 6 | #include "mbed.h" |
BalB | 0:1d2060237094 | 7 | AnalogIn top_left(A0); // Analog InPut |
BalB | 0:1d2060237094 | 8 | AnalogIn top_right(A1); // Analog InPut |
BalB | 0:1d2060237094 | 9 | AnalogIn bot_left(A2); // Analog InPut |
BalB | 0:1d2060237094 | 10 | AnalogIn bot_right(A3); // Analog InPut |
BalB | 0:1d2060237094 | 11 | |
BalB | 0:1d2060237094 | 12 | |
BalB | 0:1d2060237094 | 13 | DigitalOut myled(LED1); // Digital OutPut |
BalB | 0:1d2060237094 | 14 | Serial pc(SERIAL_TX, SERIAL_RX); // Default USART is: 8N1 NO FlowControl |
BalB | 0:1d2060237094 | 15 | // Variables -------------------------------------------------------------- |
BalB | 0:1d2060237094 | 16 | uint16_t meas = 0; |
BalB | 0:1d2060237094 | 17 | float_t Result_V = 0; |
BalB | 0:1d2060237094 | 18 | float_t MinStepRes = 0; |
BalB | 0:1d2060237094 | 19 | //DigitalOut led(LED1); |
BalB | 0:1d2060237094 | 20 | |
BalB | 0:1d2060237094 | 21 | |
BalB | 0:1d2060237094 | 22 | // ATTENTION |
BalB | 0:1d2060237094 | 23 | // The two value below, must be changed in according to the Vcc and ADC |
BalB | 0:1d2060237094 | 24 | // resolution |
BalB | 0:1d2060237094 | 25 | float_t Valim = 3300; // This is the supplay voltage of ADC (or MCU) |
BalB | 0:1d2060237094 | 26 | float_t ADCres = 4096; // This is the ADC resolution that in this case si 12Bit |
BalB | 0:1d2060237094 | 27 | // All NUCLEO boards use an ADC with 12bit resolution |
BalB | 0:1d2060237094 | 28 | |
BalB | 0:1d2060237094 | 29 | int main() |
BalB | 0:1d2060237094 | 30 | { |
BalB | 0:1d2060237094 | 31 | pc.printf("\n\r\n\rSTART program\n\r"); |
BalB | 0:1d2060237094 | 32 | while(1) |
BalB | 0:1d2060237094 | 33 | { |
BalB | 0:1d2060237094 | 34 | // Read the analog input value |
BalB | 0:1d2060237094 | 35 | measTL = top_left.read_u16(); |
BalB | 0:1d2060237094 | 36 | measTR = top_right.read_u16(); |
BalB | 0:1d2060237094 | 37 | measBL = bot_left.read_u16(); |
BalB | 0:1d2060237094 | 38 | measBR = bot_right.read_u16(); |
BalB | 0:1d2060237094 | 39 | |
BalB | 0:1d2060237094 | 40 | // Display the result via Virtual COM |
BalB | 0:1d2060237094 | 41 | pc.printf("TOP_LEFT == %d || TOP_RIGHT == %d || BOT_LEFT == %d || BOT_RIGHT == %d ", measTL, measTR , measBL, measBR); |
BalB | 0:1d2060237094 | 42 | |
BalB | 0:1d2060237094 | 43 | wait(0.8); // 800 ms |
BalB | 0:1d2060237094 | 44 | } |
BalB | 0:1d2060237094 | 45 | } |
BalB | 0:1d2060237094 | 46 | |
BalB | 0:1d2060237094 | 47 | |
BalB | 0:1d2060237094 | 48 | /*int main() { |
BalB | 0:1d2060237094 | 49 | float meas; |
BalB | 0:1d2060237094 | 50 | |
BalB | 0:1d2060237094 | 51 | printf("\nAnalogIn example\n"); |
BalB | 0:1d2060237094 | 52 | |
BalB | 0:1d2060237094 | 53 | while(1) { |
BalB | 0:1d2060237094 | 54 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
BalB | 0:1d2060237094 | 55 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
BalB | 0:1d2060237094 | 56 | printf("measure = %.0f mV\n", meas); |
BalB | 0:1d2060237094 | 57 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
BalB | 0:1d2060237094 | 58 | led = 1; |
BalB | 0:1d2060237094 | 59 | } |
BalB | 0:1d2060237094 | 60 | else { |
BalB | 0:1d2060237094 | 61 | led = 0; |
BalB | 0:1d2060237094 | 62 | } |
BalB | 0:1d2060237094 | 63 | wait(0.2); // 200 ms |
BalB | 0:1d2060237094 | 64 | } |
BalB | 0:1d2060237094 | 65 | }*/ |