![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
embedded mulmeter
Dependencies: INA219 SDFileSystem mbed
Fork of INA219-HelloWorld by
main.cpp@1:a39067e83bd8, 2016-03-30 (annotated)
- Committer:
- MLev
- Date:
- Wed Mar 30 15:14:33 2016 +0000
- Revision:
- 1:a39067e83bd8
- Parent:
- 0:363487963041
hop !
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
melse | 0:363487963041 | 1 | #include "mbed.h" |
melse | 0:363487963041 | 2 | #include "INA219.hpp" |
MLev | 1:a39067e83bd8 | 3 | #include "SDFileSystem.h" |
melse | 0:363487963041 | 4 | |
melse | 0:363487963041 | 5 | Serial pc(USBTX, USBRX); |
melse | 0:363487963041 | 6 | |
melse | 0:363487963041 | 7 | // Get this to work with the INA219 Breakout from Adafruit |
MLev | 1:a39067e83bd8 | 8 | INA219 ina219(D14, D15, 0x40, 400000, RES_10BITS); |
melse | 0:363487963041 | 9 | |
MLev | 1:a39067e83bd8 | 10 | DigitalOut led_red(LED_RED); |
MLev | 1:a39067e83bd8 | 11 | DigitalOut led_green(LED_GREEN); |
MLev | 1:a39067e83bd8 | 12 | DigitalIn sw3(SW3); |
MLev | 1:a39067e83bd8 | 13 | |
MLev | 1:a39067e83bd8 | 14 | int a; |
melse | 0:363487963041 | 15 | |
MLev | 1:a39067e83bd8 | 16 | int check_sw3(void) |
melse | 0:363487963041 | 17 | { |
MLev | 1:a39067e83bd8 | 18 | if (sw3 == 0) { |
MLev | 1:a39067e83bd8 | 19 | printf("SW2 button pressed. \n"); |
MLev | 1:a39067e83bd8 | 20 | a = 1; |
MLev | 1:a39067e83bd8 | 21 | }else a =0; |
melse | 0:363487963041 | 22 | |
MLev | 1:a39067e83bd8 | 23 | return a; |
melse | 0:363487963041 | 24 | } |
melse | 0:363487963041 | 25 | |
melse | 0:363487963041 | 26 | int main(void) |
melse | 0:363487963041 | 27 | { |
MLev | 1:a39067e83bd8 | 28 | pc.baud(9600); |
MLev | 1:a39067e83bd8 | 29 | //printf("\n 1234234 hello\n"); |
MLev | 1:a39067e83bd8 | 30 | //float refresh_interval = 1/refresh_rate; |
MLev | 1:a39067e83bd8 | 31 | |
MLev | 1:a39067e83bd8 | 32 | printf("hello this is the current and voltage of our circuit\r\n\n"); |
MLev | 1:a39067e83bd8 | 33 | float volt; |
MLev | 1:a39067e83bd8 | 34 | float current_ma; |
MLev | 1:a39067e83bd8 | 35 | |
MLev | 1:a39067e83bd8 | 36 | if((fp1 != NULL) && (fp2 != NULL)) |
MLev | 1:a39067e83bd8 | 37 | { |
MLev | 1:a39067e83bd8 | 38 | led_green = 0; // |
MLev | 1:a39067e83bd8 | 39 | led_red = 1; |
MLev | 1:a39067e83bd8 | 40 | a = 0; |
MLev | 1:a39067e83bd8 | 41 | while(a == 0){ |
MLev | 1:a39067e83bd8 | 42 | volt= ina219.read_bus_voltage(); |
MLev | 1:a39067e83bd8 | 43 | current_ma = ina219.read_current_mA(); |
MLev | 1:a39067e83bd8 | 44 | |
MLev | 1:a39067e83bd8 | 45 | printf("\r volt :%f\n", volt); |
MLev | 1:a39067e83bd8 | 46 | printf("\r courant : %f\n\n", current_ma); |
MLev | 1:a39067e83bd8 | 47 | |
MLev | 1:a39067e83bd8 | 48 | wait(5); |
MLev | 1:a39067e83bd8 | 49 | a = check_sw3(); |
MLev | 1:a39067e83bd8 | 50 | } |
MLev | 1:a39067e83bd8 | 51 | } |
melse | 0:363487963041 | 52 | |
MLev | 1:a39067e83bd8 | 53 | led_red = 0; // on |
MLev | 1:a39067e83bd8 | 54 | led_green = 1; // off |
MLev | 1:a39067e83bd8 | 55 | |
MLev | 1:a39067e83bd8 | 56 | |
melse | 0:363487963041 | 57 | } |