![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Magang KRTMI Day 1 : Program Motor Driver Nucleo
Dependencies: mbed
main.cpp@0:7a67707b5b88, 2019-03-20 (annotated)
- Committer:
- tifanysaulina
- Date:
- Wed Mar 20 16:55:17 2019 +0000
- Revision:
- 0:7a67707b5b88
yup
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tifanysaulina | 0:7a67707b5b88 | 1 | #include "mbed.h" |
tifanysaulina | 0:7a67707b5b88 | 2 | |
tifanysaulina | 0:7a67707b5b88 | 3 | AnalogIn analog_value(A0); |
tifanysaulina | 0:7a67707b5b88 | 4 | |
tifanysaulina | 0:7a67707b5b88 | 5 | DigitalOut led(LED1); |
tifanysaulina | 0:7a67707b5b88 | 6 | |
tifanysaulina | 0:7a67707b5b88 | 7 | int main() { |
tifanysaulina | 0:7a67707b5b88 | 8 | float meas; |
tifanysaulina | 0:7a67707b5b88 | 9 | |
tifanysaulina | 0:7a67707b5b88 | 10 | printf("\nAnalogIn example\n"); |
tifanysaulina | 0:7a67707b5b88 | 11 | |
tifanysaulina | 0:7a67707b5b88 | 12 | while(1) { |
tifanysaulina | 0:7a67707b5b88 | 13 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
tifanysaulina | 0:7a67707b5b88 | 14 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
tifanysaulina | 0:7a67707b5b88 | 15 | printf("measure = %.0f mV\n", meas); |
tifanysaulina | 0:7a67707b5b88 | 16 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
tifanysaulina | 0:7a67707b5b88 | 17 | led = 1; |
tifanysaulina | 0:7a67707b5b88 | 18 | } |
tifanysaulina | 0:7a67707b5b88 | 19 | else { |
tifanysaulina | 0:7a67707b5b88 | 20 | led = 0; |
tifanysaulina | 0:7a67707b5b88 | 21 | } |
tifanysaulina | 0:7a67707b5b88 | 22 | wait(0.2); // 200 ms |
tifanysaulina | 0:7a67707b5b88 | 23 | } |
tifanysaulina | 0:7a67707b5b88 | 24 | } |