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

Dependencies:   TextLCD mbed MultiSerial Pswitch_Lib

Committer:
lilac0112_1
Date:
Thu Sep 04 22:17:32 2014 +0000
Revision:
2:7820849bf534
Parent:
1:84625a611c5f
Child:
3:cfd7cd361088
????

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