LPC1114FN28 drive 8x8 LED Matrix. http://jiwashin.blogspot.jp/2016/07/my-lpc1114-device-lose-before-game.html
main.cpp@0:070e4cb87478, 2015-06-27 (annotated)
- Committer:
- TareObjects
- Date:
- Sat Jun 27 07:51:45 2015 +0000
- Revision:
- 0:070e4cb87478
- Child:
- 1:badc825f9c7e
side scroll numbers is ok!; ?????????????????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TareObjects | 0:070e4cb87478 | 1 | #include "mbed.h" |
TareObjects | 0:070e4cb87478 | 2 | |
TareObjects | 0:070e4cb87478 | 3 | |
TareObjects | 0:070e4cb87478 | 4 | char num0[] = {126,129,129,129,129,129,126,0}; |
TareObjects | 0:070e4cb87478 | 5 | char num1[] = {0,1,65,255,1,1,0,0}; |
TareObjects | 0:070e4cb87478 | 6 | char num2[] = {33,67,133,137,137,113,1,0}; |
TareObjects | 0:070e4cb87478 | 7 | char num3[] = {66,129,145,145,145,145,110,0}; |
TareObjects | 0:070e4cb87478 | 8 | char num4[] = {24,40,72,136,8,255,8,0}; |
TareObjects | 0:070e4cb87478 | 9 | char num5[] = {242,145,145,145,145,145,142,0}; |
TareObjects | 0:070e4cb87478 | 10 | char num6[] = {126,145,145,145,145,145,78,0}; |
TareObjects | 0:070e4cb87478 | 11 | char num7[] = {192,128,128,143,144,160,192,0}; |
TareObjects | 0:070e4cb87478 | 12 | char num8[] = {110,145,145,145,145,145,110,0}; |
TareObjects | 0:070e4cb87478 | 13 | char num9[] = {114,137,137,137,137,137,126,0}; |
TareObjects | 0:070e4cb87478 | 14 | |
TareObjects | 0:070e4cb87478 | 15 | |
TareObjects | 0:070e4cb87478 | 16 | char *nums[] = {num0, num1, num2, num3, num4, num5, num6, num7, num8, num9}; |
TareObjects | 0:070e4cb87478 | 17 | |
TareObjects | 0:070e4cb87478 | 18 | //BusOut common(dp15,dp25,dp13,dp17, dp1,dp11, dp2); // anode |
TareObjects | 0:070e4cb87478 | 19 | //BusOut row( dp18, dp4, dp6,dp14,dp10,dp16,dp26,dp28); // casode |
TareObjects | 0:070e4cb87478 | 20 | BusOut common( dp9, dp2, dp11, dp1, dp17, dp13, dp25, dp15); // anode |
TareObjects | 0:070e4cb87478 | 21 | BusOut row( dp28, dp26, dp16, dp10, dp14, dp6, dp4, dp18); // casode |
TareObjects | 0:070e4cb87478 | 22 | |
TareObjects | 0:070e4cb87478 | 23 | |
TareObjects | 0:070e4cb87478 | 24 | |
TareObjects | 0:070e4cb87478 | 25 | Ticker frameRate; |
TareObjects | 0:070e4cb87478 | 26 | Ticker dynamicRate; |
TareObjects | 0:070e4cb87478 | 27 | |
TareObjects | 0:070e4cb87478 | 28 | |
TareObjects | 0:070e4cb87478 | 29 | char *displayBuffer = "9876543210"; |
TareObjects | 0:070e4cb87478 | 30 | int nDisplayBuffer; |
TareObjects | 0:070e4cb87478 | 31 | int iDisplayBuffer = 0; |
TareObjects | 0:070e4cb87478 | 32 | char *pNumLeft; // 出力中の数字ビットパターン、左側 |
TareObjects | 0:070e4cb87478 | 33 | char *pNumRight; // 出力中の数字ビットパターン、右側 |
TareObjects | 0:070e4cb87478 | 34 | int iShift = 0; // 0 - 7 ... 現在何ビットずれているか |
TareObjects | 0:070e4cb87478 | 35 | |
TareObjects | 0:070e4cb87478 | 36 | |
TareObjects | 0:070e4cb87478 | 37 | void setPNumLeftAndRight() { |
TareObjects | 0:070e4cb87478 | 38 | char left = displayBuffer[iDisplayBuffer]; |
TareObjects | 0:070e4cb87478 | 39 | pNumLeft = nums[left - '0']; |
TareObjects | 0:070e4cb87478 | 40 | char right = (iDisplayBuffer+1 >= nDisplayBuffer) ? displayBuffer[0] : displayBuffer[iDisplayBuffer+1]; |
TareObjects | 0:070e4cb87478 | 41 | pNumRight = nums[right - '0']; |
TareObjects | 0:070e4cb87478 | 42 | } |
TareObjects | 0:070e4cb87478 | 43 | |
TareObjects | 0:070e4cb87478 | 44 | void dynamicDriver(); |
TareObjects | 0:070e4cb87478 | 45 | |
TareObjects | 0:070e4cb87478 | 46 | |
TareObjects | 0:070e4cb87478 | 47 | void count() { |
TareObjects | 0:070e4cb87478 | 48 | dynamicRate.detach(); |
TareObjects | 0:070e4cb87478 | 49 | |
TareObjects | 0:070e4cb87478 | 50 | iShift++; |
TareObjects | 0:070e4cb87478 | 51 | if (iShift >= 8) { |
TareObjects | 0:070e4cb87478 | 52 | iShift = 0; |
TareObjects | 0:070e4cb87478 | 53 | |
TareObjects | 0:070e4cb87478 | 54 | iDisplayBuffer++; |
TareObjects | 0:070e4cb87478 | 55 | if (iDisplayBuffer >= nDisplayBuffer) { |
TareObjects | 0:070e4cb87478 | 56 | iDisplayBuffer = 0; |
TareObjects | 0:070e4cb87478 | 57 | } |
TareObjects | 0:070e4cb87478 | 58 | setPNumLeftAndRight(); |
TareObjects | 0:070e4cb87478 | 59 | } |
TareObjects | 0:070e4cb87478 | 60 | |
TareObjects | 0:070e4cb87478 | 61 | dynamicRate.attach(dynamicDriver, 0.0001); |
TareObjects | 0:070e4cb87478 | 62 | } |
TareObjects | 0:070e4cb87478 | 63 | |
TareObjects | 0:070e4cb87478 | 64 | |
TareObjects | 0:070e4cb87478 | 65 | int iYoko = 0; |
TareObjects | 0:070e4cb87478 | 66 | int pYoko = 1; |
TareObjects | 0:070e4cb87478 | 67 | |
TareObjects | 0:070e4cb87478 | 68 | |
TareObjects | 0:070e4cb87478 | 69 | void dynamicDriver() { |
TareObjects | 0:070e4cb87478 | 70 | int i = iYoko + iShift; |
TareObjects | 0:070e4cb87478 | 71 | |
TareObjects | 0:070e4cb87478 | 72 | common = 0x00; |
TareObjects | 0:070e4cb87478 | 73 | // char rowData = (i < 8) ? iShift : iShift*16; |
TareObjects | 0:070e4cb87478 | 74 | // char rowData = (i < 8) ? num0[iShift] : num1[iShift]; |
TareObjects | 0:070e4cb87478 | 75 | char rowData = (i < 8) ? pNumLeft[i] : pNumRight[i % 8]; |
TareObjects | 0:070e4cb87478 | 76 | row = (~rowData) & 0x00ff; |
TareObjects | 0:070e4cb87478 | 77 | common = (pYoko) & 0x00ff; |
TareObjects | 0:070e4cb87478 | 78 | iYoko++; |
TareObjects | 0:070e4cb87478 | 79 | pYoko *= 2; |
TareObjects | 0:070e4cb87478 | 80 | if (iYoko == 8) { |
TareObjects | 0:070e4cb87478 | 81 | iYoko = 0; |
TareObjects | 0:070e4cb87478 | 82 | pYoko = 1; |
TareObjects | 0:070e4cb87478 | 83 | } |
TareObjects | 0:070e4cb87478 | 84 | } |
TareObjects | 0:070e4cb87478 | 85 | |
TareObjects | 0:070e4cb87478 | 86 | |
TareObjects | 0:070e4cb87478 | 87 | int main() { |
TareObjects | 0:070e4cb87478 | 88 | nDisplayBuffer = strlen(displayBuffer); |
TareObjects | 0:070e4cb87478 | 89 | |
TareObjects | 0:070e4cb87478 | 90 | iDisplayBuffer = 0; |
TareObjects | 0:070e4cb87478 | 91 | iShift = 0; |
TareObjects | 0:070e4cb87478 | 92 | setPNumLeftAndRight(); |
TareObjects | 0:070e4cb87478 | 93 | |
TareObjects | 0:070e4cb87478 | 94 | frameRate.attach(count, 0.05); |
TareObjects | 0:070e4cb87478 | 95 | dynamicRate.attach(dynamicDriver, 0.0001); |
TareObjects | 0:070e4cb87478 | 96 | |
TareObjects | 0:070e4cb87478 | 97 | |
TareObjects | 0:070e4cb87478 | 98 | while(1) { |
TareObjects | 0:070e4cb87478 | 99 | wait(1); |
TareObjects | 0:070e4cb87478 | 100 | } |
TareObjects | 0:070e4cb87478 | 101 | } |