This program is for "LEDCUBE4mbed". You can change the mode for changing the value of "debug".
Dependencies: ConfigFile FatFileSystem SDFileSystem mbed
main.cpp@1:0991aefbe7be, 2012-08-09 (annotated)
- Committer:
- ds074704261
- Date:
- Thu Aug 09 09:01:48 2012 +0000
- Revision:
- 1:0991aefbe7be
- Parent:
- 0:bedae49a4612
- Child:
- 2:96833c69287d
Test with LED.; Set LEDs to p21-p25.
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:bedae49a4612 | 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 | 0:bedae49a4612 | 33 | |
ds074704261 | 0:bedae49a4612 | 34 | /* ================================================== |
ds074704261 | 0:bedae49a4612 | 35 | * Not implemented |
ds074704261 | 0:bedae49a4612 | 36 | * ================================================== |
ds074704261 | 0:bedae49a4612 | 37 | */ |
ds074704261 | 0:bedae49a4612 | 38 | //AnalogIn volume(p20); |
ds074704261 | 0:bedae49a4612 | 39 | /* |
ds074704261 | 0:bedae49a4612 | 40 | // MicroSD Ssytem |
ds074704261 | 0:bedae49a4612 | 41 | #include "SDFileSystem.h" |
ds074704261 | 0:bedae49a4612 | 42 | #define SD_MOSI p5 |
ds074704261 | 0:bedae49a4612 | 43 | #define SD_MISO p6 |
ds074704261 | 0:bedae49a4612 | 44 | #define SD_SCLK p7 |
ds074704261 | 0:bedae49a4612 | 45 | #define SD_CS p8 |
ds074704261 | 0:bedae49a4612 | 46 | |
ds074704261 | 0:bedae49a4612 | 47 | //SDFileSystem sd(p5, p6, p7, p13, "sd"); // mosi, miso, sclk, cs, name |
ds074704261 | 0:bedae49a4612 | 48 | SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCLK, SD_CS, "sd"); // mosi, miso, sclk, cs, name (HW modification candidate) |
ds074704261 | 0:bedae49a4612 | 49 | */ |
ds074704261 | 0:bedae49a4612 | 50 | |
ds074704261 | 0:bedae49a4612 | 51 | void resetColumn() { |
ds074704261 | 0:bedae49a4612 | 52 | |
ds074704261 | 0:bedae49a4612 | 53 | } |
ds074704261 | 0:bedae49a4612 | 54 | |
ds074704261 | 0:bedae49a4612 | 55 | int main() { |
ds074704261 | 0:bedae49a4612 | 56 | |
ds074704261 | 0:bedae49a4612 | 57 | //error |
ds074704261 | 0:bedae49a4612 | 58 | if (!cfg.read("/local/pattern.cfg")) { |
ds074704261 | 0:bedae49a4612 | 59 | printf("Failure to read a configuration file.\n"); |
ds074704261 | 0:bedae49a4612 | 60 | while(1){ |
ds074704261 | 0:bedae49a4612 | 61 | leds = 15; |
ds074704261 | 0:bedae49a4612 | 62 | wait(0.1); |
ds074704261 | 0:bedae49a4612 | 63 | leds = 0; |
ds074704261 | 0:bedae49a4612 | 64 | wait(0.1); |
ds074704261 | 0:bedae49a4612 | 65 | } |
ds074704261 | 0:bedae49a4612 | 66 | } |
ds074704261 | 0:bedae49a4612 | 67 | |
ds074704261 | 0:bedae49a4612 | 68 | //read file |
ds074704261 | 0:bedae49a4612 | 69 | printf("reading file...\n"); |
ds074704261 | 0:bedae49a4612 | 70 | cfg.read("/local/pattern.cfg"); |
ds074704261 | 0:bedae49a4612 | 71 | |
ds074704261 | 0:bedae49a4612 | 72 | const int cnt = cfg.getCount(); |
ds074704261 | 0:bedae49a4612 | 73 | char buf_key[BUFSIZ]; |
ds074704261 | 0:bedae49a4612 | 74 | char buf_value[BUFSIZ]; |
ds074704261 | 0:bedae49a4612 | 75 | |
ds074704261 | 0:bedae49a4612 | 76 | long sin2; |
ds074704261 | 0:bedae49a4612 | 77 | |
ds074704261 | 0:bedae49a4612 | 78 | for (int i = 0; i < cnt; i++) { |
ds074704261 | 1:0991aefbe7be | 79 | leds = 0; |
ds074704261 | 0:bedae49a4612 | 80 | if (cfg.getKeyAndValue(i, buf_key, sizeof(buf_key), buf_value, sizeof(buf_value))) { |
ds074704261 | 0:bedae49a4612 | 81 | //printf("No.%3d:'%s'='%s'\n", i, buf_key, buf_value); |
ds074704261 | 0:bedae49a4612 | 82 | |
ds074704261 | 0:bedae49a4612 | 83 | sin2 = strtol(buf_value, NULL, 2); |
ds074704261 | 0:bedae49a4612 | 84 | printf("%d = %d\n", i+1, sin2); |
ds074704261 | 0:bedae49a4612 | 85 | |
ds074704261 | 1:0991aefbe7be | 86 | C5 = sin2 & 0x1; |
ds074704261 | 1:0991aefbe7be | 87 | C4 = (sin2 >> 1) & 0x1; |
ds074704261 | 1:0991aefbe7be | 88 | C3 = (sin2 >> 2) & 0x1; |
ds074704261 | 1:0991aefbe7be | 89 | C2 = (sin2 >> 3) & 0x1; |
ds074704261 | 1:0991aefbe7be | 90 | C1 = (sin2 >> 4) & 0x1; |
ds074704261 | 1:0991aefbe7be | 91 | |
ds074704261 | 1:0991aefbe7be | 92 | leds = 1; |
ds074704261 | 1:0991aefbe7be | 93 | wait(0.1); |
ds074704261 | 1:0991aefbe7be | 94 | leds = 0; |
ds074704261 | 1:0991aefbe7be | 95 | wait(0.4); |
ds074704261 | 1:0991aefbe7be | 96 | |
ds074704261 | 0:bedae49a4612 | 97 | } else { |
ds074704261 | 0:bedae49a4612 | 98 | printf("No.%3d:Failure to get a configuration.\n", i); |
ds074704261 | 0:bedae49a4612 | 99 | } |
ds074704261 | 0:bedae49a4612 | 100 | } |
ds074704261 | 0:bedae49a4612 | 101 | } |