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: TextLCD mbed MultiSerial Pswitch_Lib
Diff: main.cpp
- Revision:
- 8:b43fbaf46e0e
- Parent:
- 7:8c15316bdba6
diff -r 8c15316bdba6 -r b43fbaf46e0e main.cpp
--- a/main.cpp Fri Sep 26 08:20:41 2014 +0000
+++ b/main.cpp Sat Oct 04 02:27:25 2014 +0000
@@ -1,17 +1,10 @@
#include "mbed.h"
#include "TextLCD.h"
#include "MultiSerial.h"
-
-/*
-strategy
-1 ソフトリセット
-2 最初の通信に割り込みを使わない
-3 MODSERIAL.hを使う
-4 __disable_irq();を使う
-*/
+
#define DATA_NUM 2
#define LINKCODE 0xCC
-#define LINK_INTERVAL 100
+#define PULSE 500
#define KEYCODE 0xAA
#define INTERVAL .5 //12
@@ -20,52 +13,42 @@
enum COMPASS{NORTH=0, EAST, SOUTH, WEST};
enum COLOR{YELLOW=0, RED, GREEN, BLUE};
-uint8_t TXdata[DATA_NUM]={0};
-uint8_t RXdata[DATA_NUM]={0};
-
-uint8_t INdata[DATA_NUM]={0};
-uint8_t EXdata[DATA_NUM]={0};
-
-volatile uint8_t count=0;
+uint8_t TXdata[DATA_NUM]={0}, RXdata[DATA_NUM]={0};
+uint8_t INdata[DATA_NUM]={0}, EXdata[DATA_NUM]={0};
+uint8_t count=0;
bool SW;
-bool GAT=1;
void SetUp();
void connect_check();
-void GiveAndTake();
uint8_t LinkBit(bool eight, bool seven, bool six, bool five, bool fore, bool three, bool two, bool one);
void illumination();
-Ticker TAX;
-
Ticker flick;
BusOut LED(LED1, LED2, LED3, LED4);
DigitalOut YLED(p6);
+DigitalIn Toggle(p5);
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);
MultiSerial Xbee(p9, p10);
-Serial pc(USBTX,USBRX);
-
+RawSerial pc(USBTX,USBRX);
int main()
{
-
SetUp();
- TAX.attach(GiveAndTake, 0.1);
- Toggle.mode(PullUp);
+ TXdata[0]=LINKCODE;
+ Xbee.start_write();
+ Xbee.write_data(TXdata,KEYCODE);
+
+ Xbee.start_read();
+ Xbee.read_data(RXdata,KEYCODE);
- while(1){
- if(RXdata[0]==LINKCODE) break;
- }
- Xbee.stop_read();
+ connect_check();
- //connect_check();
-
+ //flick.attach(illumination, INTERVAL);
TextLCD lcd(p26, p25, p24, p23, p22, p21, TextLCD::LCD16x2); // rs, e, d4-d7
if(TXdata[0]==LINKCODE) lcd.cls(), lcd.printf("3SecondsLater,\n YouCanRun");
@@ -81,10 +64,19 @@
YLED=!Toggle;
+ /*if(!Toggle){
+ flick.detach();
+ LED=0;
+ }else{
+ flick.attach(illumination, INTERVAL);
+ }*/
+
+ if(E)
+
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){
+ /*if(Toggle){
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]);
@@ -97,7 +89,6 @@
}
}
-
void SetUp(void){
CrossKey[NORTH][RIGHT].mode(PullUp);
@@ -114,64 +105,26 @@
SideKey[INDEX][LEFT].mode(PullUp);
SideKey[MIDDLE][LEFT].mode(PullUp);
- flick.attach(illumination, INTERVAL);
- flick.detach();
+ Toggle.mode(PullUp);
}
void connect_check(void){
while(1){
YLED = !Toggle;
- LED = 12;
Xbee.start_write();
TXdata[0]=LINKCODE;
Xbee.write_data(TXdata,KEYCODE);
- //wait_ms(100);
+ LED=15;
+ wait_ms(PULSE);
Xbee.stop_write();
-
- LED = 3;
-
- Xbee.start_read();
-
- Xbee.read_data(RXdata,KEYCODE);
- //wait_ms(100);
- Xbee.stop_read();
+ LED=0;
+ wait_ms(PULSE);
if(RXdata[0]==LINKCODE) break;
-
- NVIC_SystemReset();
- }
-
-}
-void GiveAndTake(){
-
- if(GAT){
- YLED = !Toggle;
- LED = 12;
-
- Xbee.stop_read();
-
- TXdata[0]=LINKCODE;
- Xbee.start_write();
- Xbee.write_data(TXdata,KEYCODE);
- }
- else{
- YLED = !Toggle;
-
- Xbee.stop_write();
-
- Xbee.start_read();
- LED = 3;
- Xbee.read_data(RXdata,KEYCODE);
-
- wait_ms(100);
-
- if(RXdata[0]==LINKCODE) TAX.detach();
- NVIC_SystemReset();
- }
- GAT = !GAT;
+ }
}
uint8_t LinkBit(bool eight, bool seven, bool six, bool five, bool fore, bool three, bool two, bool one){//0と1を集めて整数を作る
return 0x80*eight + 0x40*seven + 0x20*six + 0x10*five + 0x08*fore + 0x04*three + 0x02*two + 0x01*one;