LPC1114FN28 drive 8x8 LED Matrix. http://jiwashin.blogspot.jp/2016/07/my-lpc1114-device-lose-before-game.html
Diff: main.cpp
- Revision:
- 3:ee5be57a4110
- Parent:
- 2:adfdb6828250
- Child:
- 4:4e98ee4a17f6
- Child:
- 5:212841923abb
--- a/main.cpp Thu Jul 09 22:24:28 2015 +0000 +++ b/main.cpp Thu Jul 30 08:58:06 2015 +0000 @@ -1,7 +1,7 @@ #include "mbed.h" #include "rtos.h" -const int deviceOffset = 0; +const int deviceOffset = 4; #define MaxReceiveBufferSize 100 @@ -37,7 +37,7 @@ I2CSlave slave(dp5, dp27); -Ticker secondRate; +//Ticker secondRate; Ticker frameRate; Ticker dynamicRate; @@ -76,63 +76,54 @@ } -int second = 0; -int minute = 0; -int hour = 0; +//int second = 0; +//int minute = 0; +//int hour = 0; +// +//// if -1 the display is shift automatically +//int autoShiftWindow = -1; +// +//void secondVector() +//{ +// second++; +// if (second >= 60) { +// second = 0; +// minute ++; +// if (minute >= 60) { +// minute = 0; +// hour++; +// if (hour >= 24) { +// hour = 0; +// } +// } +// } +// +// if (autoShiftWindow != -1) { +// autoShiftWindow++; +// } +//} -// if -1 the display is shift automatically -int autoShiftWindow = -1; -void secondVector() +void shiftVector(const void* arg) { - second++; - if (second >= 60) { - second = 0; - minute ++; - if (minute >= 60) { - minute = 0; - hour++; - if (hour >= 24) { - hour = 0; - } + iShift++; + if (iShift >= 8) { + iShift = 0; + + iDisplayBuffer++; + if (iDisplayBuffer >= nDisplayBuffer) { + iDisplayBuffer = 0; } - } - - if (autoShiftWindow != -1) { - autoShiftWindow++; + setPNumLeftAndRight(); } } -void shiftVector() -{ - disableTicker(); - - if (autoShiftWindow == -1) { - iShift++; - if (iShift >= 8) { - iShift = 0; - - iDisplayBuffer++; - if (iDisplayBuffer >= nDisplayBuffer) { - iDisplayBuffer = 0; - } - setPNumLeftAndRight(); - } - } else { - if (autoShiftWindow >= 60) { - autoShiftWindow = 0; - } - } - enableTicker(); -} +static int iYoko = 0; +static int pYoko = 1; -int iYoko = 0; -int pYoko = 1; - - -void dynamicVector() +void dynamicVector(void const* arg) { int i = iYoko + iShift; @@ -149,19 +140,19 @@ } -void disableTicker() -{ - secondRate.detach(); - frameRate.detach(); - dynamicRate.detach(); -} +//void disableTicker() +//{ +// secondRate.detach(); +// frameRate.detach(); +// dynamicRate.detach(); +//} -void enableTicker() -{ - secondRate.attach(secondVector, 1.0000); - frameRate.attach(shiftVector, 0.0500); - dynamicRate.attach(dynamicVector, 0.0001); -} +//void enableTicker() +//{ +// secondRate.attach(secondVector, 1.0000); +// frameRate.attach(shiftVector, 0.0500); +// dynamicRate.attach(dynamicVector, 0.0001); +//} static char buf[MaxReceiveBufferSize]; @@ -169,19 +160,21 @@ { slave.address(0x10 + deviceOffset); - strcpy(displayBuffer, " :3: "); - displayBuffer[2] = deviceOffset + '0'; + strcpy(displayBuffer, "x "); + displayBuffer[0] = deviceOffset + '0'; nDisplayBuffer = strlen(displayBuffer); iDisplayBuffer = 0; iShift = 0; setPNumLeftAndRight(); - enableTicker(); - -// char buf[100]; -// char *msg = "ok"; - + RtosTimer dynamicTimer(dynamicVector, osTimerPeriodic); + dynamicTimer.start(1); + + RtosTimer frameRate(shiftVector, osTimerPeriodic); + frameRate.start(50); + int demoMode = true; + while(1) { int status = slave.receive(); int charPos, shiftPos; @@ -190,29 +183,14 @@ // slave.write(msg, strlen(msg) + 1); // Includes null char // break; -// case I2CSlave::WriteGeneral: -// disableTicker(); -// if (slave.read(buf, 2)) { -// autoShiftWindow = 0; // stop automatic shift -// -// charPos = buf[0] - '0'; -// shiftPos = buf[1] - '0'; -// -// if (charPos >= 0 && charPos < nDisplayBuffer) { -// iDisplayBuffer = charPos; -// } -// if (shiftPos >= 0 && shiftPos < 8) { -// iShift = shiftPos; -// } -// } -// enableTicker(); -// break; - + case I2CSlave::WriteGeneral: case I2CSlave::WriteAddressed: - disableTicker(); + if (demoMode) { + frameRate.stop(); + demoMode = false; + } if (slave.read(buf, MaxReceiveBufferSize)) { if (buf[0] == 'x') { - autoShiftWindow = 0; // stop automatic shift charPos = buf[1] - '0'; shiftPos = buf[2] - '0'; @@ -227,16 +205,15 @@ displayBuffer[MaxReceiveBufferSize-1] = 0; nDisplayBuffer = strlen(displayBuffer); if (iDisplayBuffer >= nDisplayBuffer) iDisplayBuffer = 0; - setPNumLeftAndRight(); } + setPNumLeftAndRight(); } - enableTicker(); break; default: + Thread::wait(1); break; } - for (int i = 0; i < MaxReceiveBufferSize; i++) buf[i] = 0; } }