This program is for "LEDCUBE4mbed". You can change the mode for changing the value of "debug".

Dependencies:   ConfigFile FatFileSystem SDFileSystem mbed

Committer:
ds074704261
Date:
Fri Aug 10 03:50:29 2012 +0000
Revision:
2:96833c69287d
Parent:
1:0991aefbe7be
Child:
3:b98db4a46561
Completed.; Start sw,Reset sw,Replay sw,Analog speed sw.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ds074704261 0:bedae49a4612 1 #include "mbed.h"
ds074704261 0:bedae49a4612 2 #include "ConfigFile.h"
ds074704261 0:bedae49a4612 3 //#include "SDFileSystem.h"
ds074704261 0:bedae49a4612 4
ds074704261 0:bedae49a4612 5 ConfigFile cfg;
ds074704261 0:bedae49a4612 6 LocalFileSystem local("local");
ds074704261 0:bedae49a4612 7
ds074704261 0:bedae49a4612 8 /*
ds074704261 0:bedae49a4612 9 * ==================================================
ds074704261 0:bedae49a4612 10 * Definition of "LINE"
ds074704261 0:bedae49a4612 11 * ==================================================
ds074704261 0:bedae49a4612 12 *
ds074704261 0:bedae49a4612 13 * C1 C2 C3 C4 C5
ds074704261 0:bedae49a4612 14 * --------------------
ds074704261 0:bedae49a4612 15 * L1 L2 L3 L4 L5
ds074704261 0:bedae49a4612 16 * L6 L7 L8 L9 L10
ds074704261 0:bedae49a4612 17 * L11 L12 L13 L14 L15
ds074704261 0:bedae49a4612 18 * L16 L17 L18 L19 L20
ds074704261 0:bedae49a4612 19 * L21 L22 L23 L24 L25
ds074704261 0:bedae49a4612 20 *
ds074704261 0:bedae49a4612 21 * ==================================================
ds074704261 0:bedae49a4612 22 */
ds074704261 0:bedae49a4612 23
ds074704261 0:bedae49a4612 24 BusOut leds(LED1, LED2, LED3, LED4);
ds074704261 0:bedae49a4612 25 DigitalOut C1(p25); //line1 to line5
ds074704261 0:bedae49a4612 26 DigitalOut C2(p24); //line6 to line10
ds074704261 0:bedae49a4612 27 DigitalOut C3(p23); //line11 to line15
ds074704261 0:bedae49a4612 28 DigitalOut C4(p22); //line16 to line20
ds074704261 0:bedae49a4612 29 DigitalOut C5(p21); //line21 to line25
ds074704261 2:96833c69287d 30 //DigitalOut Call[] = {p25, p24, p23, p22, p21};
ds074704261 0:bedae49a4612 31 DigitalOut mclock(p5); //mainclock
ds074704261 0:bedae49a4612 32 DigitalOut sclock(p6); //subclock
ds074704261 2:96833c69287d 33 AnalogIn volume(p20);
ds074704261 2:96833c69287d 34 DigitalIn resets(p19);
ds074704261 2:96833c69287d 35 DigitalIn replay(p18);
ds074704261 2:96833c69287d 36 DigitalIn start(p17);
ds074704261 2:96833c69287d 37
ds074704261 0:bedae49a4612 38
ds074704261 0:bedae49a4612 39 /* ==================================================
ds074704261 0:bedae49a4612 40 * Not implemented
ds074704261 0:bedae49a4612 41 * ==================================================
ds074704261 2:96833c69287d 42
ds074704261 0:bedae49a4612 43 // MicroSD Ssytem
ds074704261 0:bedae49a4612 44 #include "SDFileSystem.h"
ds074704261 0:bedae49a4612 45 #define SD_MOSI p5
ds074704261 0:bedae49a4612 46 #define SD_MISO p6
ds074704261 0:bedae49a4612 47 #define SD_SCLK p7
ds074704261 0:bedae49a4612 48 #define SD_CS p8
ds074704261 0:bedae49a4612 49
ds074704261 2:96833c69287d 50 //SDFileSystem sd(p11, p12, p13, p9, "sd"); // mosi, miso, sclk, cs, name
ds074704261 0:bedae49a4612 51 SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCLK, SD_CS, "sd"); // mosi, miso, sclk, cs, name (HW modification candidate)
ds074704261 0:bedae49a4612 52 */
ds074704261 0:bedae49a4612 53
ds074704261 0:bedae49a4612 54 int main() {
ds074704261 2:96833c69287d 55 while(1){
ds074704261 2:96833c69287d 56 if(start == 1){
ds074704261 2:96833c69287d 57 goto replay;
ds074704261 2:96833c69287d 58 } else {
ds074704261 2:96833c69287d 59 leds = 8;
ds074704261 2:96833c69287d 60 wait_ms(50);
ds074704261 2:96833c69287d 61 leds = 0;
ds074704261 2:96833c69287d 62 wait_ms(50);
ds074704261 2:96833c69287d 63 }//else
ds074704261 2:96833c69287d 64 }//while
ds074704261 2:96833c69287d 65 replay:
ds074704261 2:96833c69287d 66 float speed = volume;
ds074704261 2:96833c69287d 67 printf("This program will Set Pattern in %f sec.\n",speed);
ds074704261 0:bedae49a4612 68 //error
ds074704261 0:bedae49a4612 69 if (!cfg.read("/local/pattern.cfg")) {
ds074704261 0:bedae49a4612 70 printf("Failure to read a configuration file.\n");
ds074704261 0:bedae49a4612 71 while(1){
ds074704261 0:bedae49a4612 72 leds = 15;
ds074704261 0:bedae49a4612 73 wait(0.1);
ds074704261 0:bedae49a4612 74 leds = 0;
ds074704261 0:bedae49a4612 75 wait(0.1);
ds074704261 0:bedae49a4612 76 }
ds074704261 0:bedae49a4612 77 }
ds074704261 0:bedae49a4612 78
ds074704261 0:bedae49a4612 79 //read file
ds074704261 0:bedae49a4612 80 printf("reading file...\n");
ds074704261 0:bedae49a4612 81 cfg.read("/local/pattern.cfg");
ds074704261 0:bedae49a4612 82
ds074704261 0:bedae49a4612 83 const int cnt = cfg.getCount();
ds074704261 0:bedae49a4612 84 char buf_key[BUFSIZ];
ds074704261 0:bedae49a4612 85 char buf_value[BUFSIZ];
ds074704261 0:bedae49a4612 86
ds074704261 0:bedae49a4612 87 long sin2;
ds074704261 0:bedae49a4612 88
ds074704261 0:bedae49a4612 89 for (int i = 0; i < cnt; i++) {
ds074704261 1:0991aefbe7be 90 leds = 0;
ds074704261 0:bedae49a4612 91 if (cfg.getKeyAndValue(i, buf_key, sizeof(buf_key), buf_value, sizeof(buf_value))) {
ds074704261 0:bedae49a4612 92
ds074704261 0:bedae49a4612 93 sin2 = strtol(buf_value, NULL, 2);
ds074704261 0:bedae49a4612 94 printf("%d = %d\n", i+1, sin2);
ds074704261 0:bedae49a4612 95
ds074704261 2:96833c69287d 96 //SetPattern
ds074704261 2:96833c69287d 97 printf("SetPattern\n");
ds074704261 2:96833c69287d 98 if((i+1) % 5 == 0){
ds074704261 2:96833c69287d 99 printf("(i+1) % 5 == 0\n");
ds074704261 2:96833c69287d 100 } else {
ds074704261 2:96833c69287d 101 C5 = sin2 & 0x1;
ds074704261 2:96833c69287d 102 C4 = (sin2 >> 1) & 0x1;
ds074704261 2:96833c69287d 103 C3 = (sin2 >> 2) & 0x1;
ds074704261 2:96833c69287d 104 C2 = (sin2 >> 3) & 0x1;
ds074704261 2:96833c69287d 105 C1 = (sin2 >> 4) & 0x1;
ds074704261 2:96833c69287d 106 printf("C1:%d,C2:%d,C3:%d,C4:%d,C5:%d\n",(sin2 >> 4) & 0x1,(sin2 >> 3) & 0x1,(sin2 >> 2) & 0x1,(sin2 >> 1) & 0x1,sin2 & 0x1);
ds074704261 2:96833c69287d 107 sclock = 1;
ds074704261 2:96833c69287d 108 leds = i+1;
ds074704261 2:96833c69287d 109 wait_ms(50);
ds074704261 2:96833c69287d 110 leds = 0;
ds074704261 2:96833c69287d 111 //Switch to Next Pattern
ds074704261 2:96833c69287d 112 if((i+1) % 5 == 4){
ds074704261 2:96833c69287d 113 mclock = 1;
ds074704261 2:96833c69287d 114 leds = 15;
ds074704261 2:96833c69287d 115 wait(volume);
ds074704261 2:96833c69287d 116 printf("Switch to Next Pattern\n");
ds074704261 2:96833c69287d 117 }
ds074704261 2:96833c69287d 118 sclock = 0;
ds074704261 2:96833c69287d 119 mclock = 0;
ds074704261 2:96833c69287d 120 }
ds074704261 0:bedae49a4612 121 } else {
ds074704261 0:bedae49a4612 122 printf("No.%3d:Failure to get a configuration.\n", i);
ds074704261 2:96833c69287d 123 }//else
ds074704261 2:96833c69287d 124 }//for
ds074704261 2:96833c69287d 125 while(1){
ds074704261 2:96833c69287d 126 if(resets == 1){
ds074704261 2:96833c69287d 127 printf("Reset!\n");
ds074704261 2:96833c69287d 128 C1 = 0;
ds074704261 2:96833c69287d 129 C2 = 0;
ds074704261 2:96833c69287d 130 C3 = 0;
ds074704261 2:96833c69287d 131 C4 = 0;
ds074704261 2:96833c69287d 132 C5 = 0;
ds074704261 2:96833c69287d 133 for(int i = 0; i < 5; i++){
ds074704261 2:96833c69287d 134 sclock = 1;
ds074704261 2:96833c69287d 135 wait_ms(10);
ds074704261 2:96833c69287d 136 sclock = 0;
ds074704261 2:96833c69287d 137 }//for
ds074704261 2:96833c69287d 138 for(int i = 0; i < 5; i++){
ds074704261 2:96833c69287d 139 mclock = 1;
ds074704261 2:96833c69287d 140 wait_ms(10);
ds074704261 2:96833c69287d 141 mclock = 0;
ds074704261 2:96833c69287d 142 }//for
ds074704261 2:96833c69287d 143 }//if
ds074704261 2:96833c69287d 144 if(replay == 1){
ds074704261 2:96833c69287d 145 goto replay;
ds074704261 0:bedae49a4612 146 }
ds074704261 2:96833c69287d 147 }//while
ds074704261 2:96833c69287d 148 }//main