for baska

Dependencies:   Hepta9axis HeptaBattery HeptaCamera_GPS HeptaTemp HeptaXbee SDFileSystem mbed

Fork of Lab1-04_model_program_1 by HEPTA-Sat Training 2017~2018

Committer:
ponpoko1939
Date:
Tue Aug 21 06:58:05 2018 +0000
Revision:
19:7d54c7b47fd8
Parent:
17:ccae1368497e
hepta_traning;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:bdbd3d6fc5d5 1 #include "mbed.h"
ponpoko1939 19:7d54c7b47fd8 2 #include "HeptaBattery.h"
umeume 2:1c5cdb2c3e0f 3
umeume 2:1c5cdb2c3e0f 4 Serial pc(USBTX,USBRX);
HEPTA 17:ccae1368497e 5
ponpoko1939 19:7d54c7b47fd8 6 DigitalOut myleds[] = {LED1,LED2,LED3,LED4};
ponpoko1939 19:7d54c7b47fd8 7 HeptaBattery battery(p16, p26);
HEPTA 17:ccae1368497e 8
HEPTA 17:ccae1368497e 9 int rcmd = 0,cmdflag = 0;
umeume 2:1c5cdb2c3e0f 10
HEPTA 17:ccae1368497e 11 void commandget()
HEPTA 17:ccae1368497e 12 {
HEPTA 17:ccae1368497e 13 rcmd=pc.getc();
HEPTA 17:ccae1368497e 14 cmdflag = 1;
HEPTA 17:ccae1368497e 15 }
HEPTA 17:ccae1368497e 16 void receive(int *xrcmd, int *xcmdflag)
HEPTA 17:ccae1368497e 17 {
HEPTA 17:ccae1368497e 18 pc.attach(commandget,Serial::RxIrq);
HEPTA 17:ccae1368497e 19 *xrcmd = rcmd;
HEPTA 17:ccae1368497e 20 *xcmdflag = cmdflag;
HEPTA 17:ccae1368497e 21 }
HEPTA 17:ccae1368497e 22
HEPTA 17:ccae1368497e 23 void initialize()
HEPTA 17:ccae1368497e 24 {
HEPTA 17:ccae1368497e 25 rcmd = 0;
HEPTA 17:ccae1368497e 26 cmdflag = 0;
HEPTA 17:ccae1368497e 27 }
umeume 5:c5ccb1b07e8f 28
umeume 2:1c5cdb2c3e0f 29 int main()
umeume 2:1c5cdb2c3e0f 30 {
HEPTA 17:ccae1368497e 31 pc.baud(9600);
ponpoko1939 19:7d54c7b47fd8 32 float bt;
ponpoko1939 19:7d54c7b47fd8 33 int flag = 0;
HEPTA 17:ccae1368497e 34 while(1) {
ponpoko1939 19:7d54c7b47fd8 35 battery.vol(&bt);
ponpoko1939 19:7d54c7b47fd8 36 if(bt <= 4.0){
ponpoko1939 19:7d54c7b47fd8 37 battery.shut_down_regulator();
ponpoko1939 19:7d54c7b47fd8 38 flag = 1;
ponpoko1939 19:7d54c7b47fd8 39 }
ponpoko1939 19:7d54c7b47fd8 40 else {
ponpoko1939 19:7d54c7b47fd8 41 battery.turn_on_regulator();
ponpoko1939 19:7d54c7b47fd8 42 flag = 0;
ponpoko1939 19:7d54c7b47fd8 43 }
ponpoko1939 19:7d54c7b47fd8 44 pc.printf("Vol = %.2f[V]\r\n",bt);
ponpoko1939 19:7d54c7b47fd8 45 if(flag == 1){
ponpoko1939 19:7d54c7b47fd8 46 pc.printf("Power savig mode ON\r\n");
ponpoko1939 19:7d54c7b47fd8 47 }
ponpoko1939 19:7d54c7b47fd8 48 wait(0.5);
HEPTA 17:ccae1368497e 49 receive(&rcmd,&cmdflag);
HEPTA 17:ccae1368497e 50 if (cmdflag == 1) {
HEPTA 17:ccae1368497e 51 if (rcmd == 'a') {
HEPTA 17:ccae1368497e 52
ponpoko1939 19:7d54c7b47fd8 53 pc.printf("Connected! = %d\n\r",rcmd);
ponpoko1939 19:7d54c7b47fd8 54 for(int i = 1;i <= 10;i++){
ponpoko1939 19:7d54c7b47fd8 55 pc.printf("%d\n\r",i);
ponpoko1939 19:7d54c7b47fd8 56 wait(1.0);
ponpoko1939 19:7d54c7b47fd8 57 }
HEPTA 17:ccae1368497e 58 }
HEPTA 17:ccae1368497e 59 initialize();
HEPTA 17:ccae1368497e 60 }
HEPTA 17:ccae1368497e 61 }
umeume 2:1c5cdb2c3e0f 62 }