受け取りのコントローラのプログラム

Dependencies:   TextLCD mbed MultiSerial Pswitch_Lib

Committer:
lilac0112_1
Date:
Tue Sep 23 08:47:33 2014 +0000
Revision:
4:39edc16ee5c3
Parent:
3:cfd7cd361088
Child:
5:a5c324942570
LCD??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lilac0112_1 0:d3702a4e32ea 1 #include "mbed.h"
lilac0112_1 0:d3702a4e32ea 2 #include "TextLCD.h"
lilac0112_1 1:84625a611c5f 3 #include "MultiSerial.h"
lilac0112_1 4:39edc16ee5c3 4 #include "Pswitch.h"
lilac0112_1 0:d3702a4e32ea 5
lilac0112_1 2:7820849bf534 6 #define DATA_NUM 2
lilac0112_1 2:7820849bf534 7 #define KEYCODE 0xAA
lilac0112_1 2:7820849bf534 8 #define INTERVAL 12
lilac0112_1 0:d3702a4e32ea 9
lilac0112_1 0:d3702a4e32ea 10 enum HAND{RIGHT=0, LEFT};
lilac0112_1 0:d3702a4e32ea 11 enum FINGER{INDEX=0, MIDDLE};
lilac0112_1 0:d3702a4e32ea 12 enum COMPASS{NORTH=0, EAST, SOUTH, WEST};
lilac0112_1 0:d3702a4e32ea 13 enum COLOR{YELLOW=0, RED, GREEN, BLUE};
lilac0112_1 0:d3702a4e32ea 14
lilac0112_1 1:84625a611c5f 15 uint8_t INdata[DATA_NUM]={0}, EXdata[DATA_NUM]={0};
lilac0112_1 0:d3702a4e32ea 16 volatile uint8_t count=0;
lilac0112_1 4:39edc16ee5c3 17 bool SW;
lilac0112_1 0:d3702a4e32ea 18
lilac0112_1 0:d3702a4e32ea 19 void SetUp();
lilac0112_1 0:d3702a4e32ea 20 uint8_t LinkBit(bool eight, bool seven, bool six, bool five, bool fore, bool three, bool two, bool one);
lilac0112_1 0:d3702a4e32ea 21 void illumination();
lilac0112_1 0:d3702a4e32ea 22
lilac0112_1 0:d3702a4e32ea 23 Ticker flick;
lilac0112_1 0:d3702a4e32ea 24 BusOut LED(LED1, LED2, LED3, LED4);
lilac0112_1 0:d3702a4e32ea 25
lilac0112_1 0:d3702a4e32ea 26 DigitalOut YLED(p6);
lilac0112_1 0:d3702a4e32ea 27
lilac0112_1 0:d3702a4e32ea 28 DigitalIn CrossKey[4][2]={{p8, p30}, {p11, p29}, {p15, p28}, {p16, p27}};//p7, p12=reserve
lilac0112_1 0:d3702a4e32ea 29 DigitalIn SideKey[2][2]={{p17, p20}, {p18, p19}};
lilac0112_1 4:39edc16ee5c3 30 Pswitch Toggle(p5);
lilac0112_1 0:d3702a4e32ea 31
lilac0112_1 1:84625a611c5f 32 MultiSerial Xbee(p9, p10, write);//or p13, p14
lilac0112_1 0:d3702a4e32ea 33 Serial pc(USBTX, USBRX);
lilac0112_1 4:39edc16ee5c3 34
lilac0112_1 0:d3702a4e32ea 35 TextLCD lcd(p26, p25, p24, p23, p22, p21, TextLCD::LCD16x2); // rs, e, d4-d7
lilac0112_1 0:d3702a4e32ea 36
lilac0112_1 0:d3702a4e32ea 37 int main() {
lilac0112_1 0:d3702a4e32ea 38
lilac0112_1 0:d3702a4e32ea 39 SetUp();
lilac0112_1 0:d3702a4e32ea 40
lilac0112_1 0:d3702a4e32ea 41 while(1) {
lilac0112_1 0:d3702a4e32ea 42
lilac0112_1 4:39edc16ee5c3 43 YLED=!Toggle.read();
lilac0112_1 4:39edc16ee5c3 44
lilac0112_1 4:39edc16ee5c3 45 if(YLED&&SW) lcd.cls(), lcd.printf("Pause Mode\n"), SW=0;
lilac0112_1 4:39edc16ee5c3 46 if((!YLED)&&(!SW)) lcd.cls(), lcd.printf("Run Mode\n"), SW=1;
lilac0112_1 4:39edc16ee5c3 47
lilac0112_1 4:39edc16ee5c3 48 if(Toggle.read()){
lilac0112_1 3:cfd7cd361088 49
lilac0112_1 3:cfd7cd361088 50 EXdata[0] = LinkBit(!CrossKey[YELLOW][LEFT], !CrossKey[RED][LEFT], !CrossKey[GREEN][LEFT], !CrossKey[BLUE][LEFT],
lilac0112_1 3:cfd7cd361088 51 !CrossKey[YELLOW][RIGHT], !CrossKey[RED][RIGHT], !CrossKey[GREEN][RIGHT], !CrossKey[BLUE][RIGHT]);
lilac0112_1 3:cfd7cd361088 52 EXdata[1] = LinkBit(0, 0, 0, 0, !SideKey[INDEX][LEFT], !SideKey[MIDDLE][LEFT], !SideKey[INDEX][RIGHT], !SideKey[MIDDLE][RIGHT]);
lilac0112_1 3:cfd7cd361088 53 }else{
lilac0112_1 3:cfd7cd361088 54
lilac0112_1 3:cfd7cd361088 55 EXdata[0] = EXdata[1] = 0x00;
lilac0112_1 3:cfd7cd361088 56 }
lilac0112_1 0:d3702a4e32ea 57
lilac0112_1 0:d3702a4e32ea 58 }
lilac0112_1 0:d3702a4e32ea 59 }
lilac0112_1 0:d3702a4e32ea 60
lilac0112_1 0:d3702a4e32ea 61 void SetUp(void){
lilac0112_1 0:d3702a4e32ea 62
lilac0112_1 2:7820849bf534 63 Xbee.write_data(EXdata, KEYCODE);
lilac0112_1 0:d3702a4e32ea 64
lilac0112_1 4:39edc16ee5c3 65 if(!Toggle.read()) lcd.cls(), lcd.printf("Pause Mode\n"), SW=0;
lilac0112_1 4:39edc16ee5c3 66 if(Toggle.read()) lcd.cls(), lcd.printf("Run Mode\n"), SW=1;
lilac0112_1 0:d3702a4e32ea 67
lilac0112_1 0:d3702a4e32ea 68 CrossKey[NORTH][RIGHT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 69 CrossKey[EAST][RIGHT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 70 CrossKey[WEST][RIGHT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 71 CrossKey[SOUTH][RIGHT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 72 CrossKey[NORTH][LEFT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 73 CrossKey[EAST][LEFT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 74 CrossKey[WEST][LEFT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 75 CrossKey[SOUTH][LEFT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 76
lilac0112_1 0:d3702a4e32ea 77 SideKey[INDEX][RIGHT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 78 SideKey[MIDDLE][RIGHT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 79 SideKey[INDEX][LEFT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 80 SideKey[MIDDLE][LEFT].mode(PullUp);
lilac0112_1 0:d3702a4e32ea 81
lilac0112_1 1:84625a611c5f 82 flick.attach(illumination, INTERVAL);
lilac0112_1 0:d3702a4e32ea 83 }
lilac0112_1 0:d3702a4e32ea 84 uint8_t LinkBit(bool eight, bool seven, bool six, bool five, bool fore, bool three, bool two, bool one){//0と1を集めて整数を作る
lilac0112_1 0:d3702a4e32ea 85 return 0x80*eight + 0x40*seven + 0x20*six + 0x10*five + 0x08*fore + 0x04*three + 0x02*two + 0x01*one;
lilac0112_1 0:d3702a4e32ea 86 }
lilac0112_1 0:d3702a4e32ea 87 void illumination(void){//literally
lilac0112_1 0:d3702a4e32ea 88 count++;
lilac0112_1 0:d3702a4e32ea 89 LED = count;
lilac0112_1 0:d3702a4e32ea 90 }