Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed CtrlStationRX
main.cpp
- Committer:
- TakushimaYukimasa
- Date:
- 2021-09-27
- Revision:
- 0:70fee422a0e0
- Child:
- 1:56c272cb4522
File content as of revision 0:70fee422a0e0:
#include "mbed.h"
#include "SO1602A.h"
#define SW_ONE(__NUM__) (SWData[__NUM__][0]-SWData[__NUM__][1]==1)
DigitalIn SW[7]= {PA_3,PA_12,PB_5,PA_11,PA_8,PF_1,PF_0};
DigitalOut POWER[2]= {PA_1,PB_1};
Serial UART(PA_9,PA_10, 9600);
DigitalOut led(LED1);
Serial telemetry(USBTX, USBRX, 115200);
SO1602A oled(PB_7,PB_6);
Timer emoTimer;
Timer restTimer;
Timer newsTimer[3];
Timer mainTimer;
int msTimer=0;
int newsStatus[3] = {0};
void uartRX()
{
char data = UART.getc();
newsStatus[(data>>2)&0b11]=(data&0b11);
newsTimer[(data>>2)&0b11].reset();
}
int main()
{
POWER[0]=POWER[1]=1;
for(int i=0; i<7; i++) SW[i].mode(PullDown);
mainTimer.reset();
mainTimer.start();
restTimer.start();
emoTimer.start();
for(int i=0; i<3; i++) newsTimer[i].start();
oled.init();
oled.setDispFlag(1,0,0);
// oled.locate(2,0);
// oled.printf("Stop display");
UART.attach(uartRX, Serial::RxIrq);
while(1) {
// telemetry.printf("%d\n\r", (SW[6]==0?0:1));
/* SW入力のワンタイム化 */
static bool SWData[7][2] = {0};
for(int i=0; i<7; i++) {
SWData[i][1]=SWData[i][0];
SWData[i][0]=SW[i];
}
/* 入力制限モード */
static bool restFlag = 0;
if(SW_ONE(0)) restFlag=!restFlag;
/* メインタイマー制御 0-pause 1-start */
static bool timerMode=0;
if(!SW[1]) timerMode=0;
if(!restFlag) {
if(SW_ONE(2)) msTimer+=1000*60;
if(SW_ONE(3)) msTimer+=1000*10;
if(SW_ONE(4)) msTimer+=1000*1;
if(SW[1]&&SW_ONE(5)) {
timerMode=0;
msTimer=0;
}
if(SW[1]&&SW_ONE(6)) timerMode=!timerMode;
}
/* 時間の更新 */
static int temp=mainTimer.read_ms();
if(timerMode) msTimer+=mainTimer.read_ms()-temp;
temp=mainTimer.read_ms();
if(msTimer>120e3){timerMode=0; msTimer=120e3;}
/* UART送受信関連 */
char sentData = (timerMode&1)<<7;
sentData |= (msTimer/1000)&0x7F;
UART.putc(sentData);
for(int i=0; i<3; i++)
if(newsTimer[i].read_ms()>500)
newsStatus[i]=0;
telemetry.printf("%d \n\r",msTimer);
/* LCD描画 */
oled.locate(5,0);
oled.printf("%1d:%02d.%d", msTimer/60000,msTimer/1000%60,msTimer/100%10);
oled.locate(0,0);
int statious=!SW[1];
if(restFlag&&(SW[2]+SW[3]+SW[4]+SW[5]+SW[6])) restTimer.reset();
if(emoTimer.read()<1&&emoTimer.read_ms()%200<100) statious=0;
if(statious) oled.printf("EMO");
else oled.printf(" ");
oled.locate(12,0);
statious=restFlag;
if(!SW[1]&&(SW[5]+SW[6])) emoTimer.reset();
if(restTimer.read()<1&&restTimer.read_ms()%200<100) statious=0;
if(statious) oled.printf("REST");
else oled.printf(" ");
for(int i=0; i<3; i++) {
oled.locate(i*6,1);
if(newsStatus[i]==0) oled.printf("Lost");
if(newsStatus[i]==1) oled.printf("None");
if(newsStatus[i]==2) oled.printf("Yoki");
}
//static Timer tim;
//tim.start();
//telemetry.printf("%d \n\r",tim.read_ms());
//tim.reset();
}
}