受け取りのコントローラのプログラム
Dependencies: TextLCD mbed MultiSerial Pswitch_Lib
Diff: main.cpp
- Revision:
- 4:39edc16ee5c3
- Parent:
- 3:cfd7cd361088
- Child:
- 5:a5c324942570
--- a/main.cpp Mon Sep 08 02:39:40 2014 +0000 +++ b/main.cpp Tue Sep 23 08:47:33 2014 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "TextLCD.h" #include "MultiSerial.h" +#include "Pswitch.h" #define DATA_NUM 2 #define KEYCODE 0xAA @@ -13,6 +14,7 @@ uint8_t INdata[DATA_NUM]={0}, EXdata[DATA_NUM]={0}; volatile uint8_t count=0; +bool SW; void SetUp(); uint8_t LinkBit(bool eight, bool seven, bool six, bool five, bool fore, bool three, bool two, bool one); @@ -25,11 +27,11 @@ DigitalIn CrossKey[4][2]={{p8, p30}, {p11, p29}, {p15, p28}, {p16, p27}};//p7, p12=reserve DigitalIn SideKey[2][2]={{p17, p20}, {p18, p19}}; -DigitalIn Toggle(p5); +Pswitch Toggle(p5); MultiSerial Xbee(p9, p10, write);//or p13, p14 Serial pc(USBTX, USBRX); - + TextLCD lcd(p26, p25, p24, p23, p22, p21, TextLCD::LCD16x2); // rs, e, d4-d7 int main() { @@ -38,8 +40,12 @@ while(1) { - YLED=!Toggle; - if(Toggle){ + YLED=!Toggle.read(); + + if(YLED&&SW) lcd.cls(), lcd.printf("Pause Mode\n"), SW=0; + if((!YLED)&&(!SW)) lcd.cls(), lcd.printf("Run Mode\n"), SW=1; + + if(Toggle.read()){ EXdata[0] = LinkBit(!CrossKey[YELLOW][LEFT], !CrossKey[RED][LEFT], !CrossKey[GREEN][LEFT], !CrossKey[BLUE][LEFT], !CrossKey[YELLOW][RIGHT], !CrossKey[RED][RIGHT], !CrossKey[GREEN][RIGHT], !CrossKey[BLUE][RIGHT]); @@ -56,7 +62,8 @@ Xbee.write_data(EXdata, KEYCODE); - lcd.printf("Hello World!\n"); + if(!Toggle.read()) lcd.cls(), lcd.printf("Pause Mode\n"), SW=0; + if(Toggle.read()) lcd.cls(), lcd.printf("Run Mode\n"), SW=1; CrossKey[NORTH][RIGHT].mode(PullUp); CrossKey[EAST][RIGHT].mode(PullUp); @@ -72,8 +79,6 @@ SideKey[INDEX][LEFT].mode(PullUp); SideKey[MIDDLE][LEFT].mode(PullUp); - Toggle.mode(PullUp); - flick.attach(illumination, INTERVAL); } uint8_t LinkBit(bool eight, bool seven, bool six, bool five, bool fore, bool three, bool two, bool one){//0と1を集めて整数を作る