rev20211120

Dependencies:   HEPTA_SENSOR mbed HEPTA_EPS HEPTA_COM HEPTA_CDH

Committer:
HeptaSatTraining2019
Date:
Wed Aug 21 18:35:31 2019 +0000
Revision:
26:220e5f95168a
Parent:
25:ccc5ff675e0c
Child:
27:06ec1277807c
Lab3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:bdbd3d6fc5d5 1 #include "mbed.h"
HeptaSatTraining2019 25:ccc5ff675e0c 2 #include "HEPTA_CDH.h"
HeptaSatTraining2019 25:ccc5ff675e0c 3 #include "HEPTA_EPS.h"
HeptaSatTraining2019 24:3659e0c223c8 4
umeume 2:1c5cdb2c3e0f 5 Serial pc(USBTX,USBRX);
HeptaSatTraining2019 26:220e5f95168a 6 HEPTA_CDH cdh(p5, p6, p7, p8, "sd");
HeptaSatTraining2019 26:220e5f95168a 7 HEPTA_EPS eps(p16,p26);
HeptaSatTraining2019 24:3659e0c223c8 8
HeptaSatTraining2019 26:220e5f95168a 9 DigitalOut myleds[] = {LED1,LED2,LED3,LED4};;
HeptaSatTraining2019 24:3659e0c223c8 10
HeptaSatTraining2019 26:220e5f95168a 11 int rcmd = 0,cmdflag = 0;
HeptaSatTraining2019 26:220e5f95168a 12
HeptaSatTraining2019 26:220e5f95168a 13 void commandget()
HeptaSatTraining2019 26:220e5f95168a 14 {
HeptaSatTraining2019 26:220e5f95168a 15 rcmd=pc.getc();
HeptaSatTraining2019 26:220e5f95168a 16 cmdflag = 1;
HeptaSatTraining2019 26:220e5f95168a 17 }
HeptaSatTraining2019 26:220e5f95168a 18 void receive(int *xrcmd, int *xcmdflag)
HeptaSatTraining2019 26:220e5f95168a 19 {
HeptaSatTraining2019 26:220e5f95168a 20 pc.attach(commandget,Serial::RxIrq);
HeptaSatTraining2019 26:220e5f95168a 21 *xrcmd = rcmd;
HeptaSatTraining2019 26:220e5f95168a 22 *xcmdflag = cmdflag;
HeptaSatTraining2019 26:220e5f95168a 23 }
HeptaSatTraining2019 26:220e5f95168a 24
HeptaSatTraining2019 26:220e5f95168a 25 void initialize()
HeptaSatTraining2019 26:220e5f95168a 26 {
HeptaSatTraining2019 26:220e5f95168a 27 rcmd = 0;
HeptaSatTraining2019 26:220e5f95168a 28 cmdflag = 0;
HeptaSatTraining2019 26:220e5f95168a 29 }
HeptaSatTraining2019 24:3659e0c223c8 30
umeume 2:1c5cdb2c3e0f 31 int main()
umeume 2:1c5cdb2c3e0f 32 {
HeptaSatTraining2019 24:3659e0c223c8 33 pc.baud(9600);
HeptaSatTraining2019 25:ccc5ff675e0c 34 float bt;
HeptaSatTraining2019 26:220e5f95168a 35 int flag = 0;
HeptaSatTraining2019 25:ccc5ff675e0c 36 char str[100];
HeptaSatTraining2019 26:220e5f95168a 37 receive(&rcmd,&cmdflag);
HeptaSatTraining2019 26:220e5f95168a 38 while(1) {
HeptaSatTraining2019 26:220e5f95168a 39 eps.vol(&bt);
HeptaSatTraining2019 26:220e5f95168a 40 if(bt <= 3.5) {
HeptaSatTraining2019 26:220e5f95168a 41 eps.shut_down_regulator();
HeptaSatTraining2019 26:220e5f95168a 42 flag = 1;
HeptaSatTraining2019 26:220e5f95168a 43 } else {
HeptaSatTraining2019 26:220e5f95168a 44 eps.turn_on_regulator();
HeptaSatTraining2019 26:220e5f95168a 45 flag = 0;
HeptaSatTraining2019 26:220e5f95168a 46 }
HeptaSatTraining2019 26:220e5f95168a 47 pc.printf("Vol = %.2f [V]\r\n",bt);
HeptaSatTraining2019 26:220e5f95168a 48 if(flag == 1) {
HeptaSatTraining2019 26:220e5f95168a 49 pc.printf("Power saving mode ON\r\n");
HeptaSatTraining2019 26:220e5f95168a 50 }
HeptaSatTraining2019 26:220e5f95168a 51 wait(0.5);
HeptaSatTraining2019 26:220e5f95168a 52 if (cmdflag == 1) {
HeptaSatTraining2019 26:220e5f95168a 53 pc.printf("Command Get = %d\r\n",rcmd);
HeptaSatTraining2019 26:220e5f95168a 54 if (rcmd == 'a') {
HeptaSatTraining2019 26:220e5f95168a 55 for(int i = 0; i < 10; i++) {
HeptaSatTraining2019 26:220e5f95168a 56 pc.printf("Count = %d\r\n",i);
HeptaSatTraining2019 26:220e5f95168a 57 wait(1.0);
HeptaSatTraining2019 26:220e5f95168a 58 }
HeptaSatTraining2019 26:220e5f95168a 59 }
HeptaSatTraining2019 26:220e5f95168a 60 if (rcmd == 'b') {
HeptaSatTraining2019 26:220e5f95168a 61
HeptaSatTraining2019 26:220e5f95168a 62
HeptaSatTraining2019 26:220e5f95168a 63
HeptaSatTraining2019 26:220e5f95168a 64
HeptaSatTraining2019 26:220e5f95168a 65
HeptaSatTraining2019 26:220e5f95168a 66
HeptaSatTraining2019 26:220e5f95168a 67 }
HeptaSatTraining2019 26:220e5f95168a 68 initialize();
HeptaSatTraining2019 26:220e5f95168a 69 }
HeptaSatTraining2019 24:3659e0c223c8 70 }
umeume 2:1c5cdb2c3e0f 71 }