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: SDFileSystem mbed
Fork of PES4_Programme by
source/main.cpp@46:cdc24a24e4e3, 2018-03-29 (annotated)
- Committer:
- aeschsim
- Date:
- Thu Mar 29 14:14:13 2018 +0000
- Revision:
- 46:cdc24a24e4e3
- Parent:
- 42:ba59ed6a2a06
- Child:
- 52:701d0c2f47d7
changed set PWM to 0...4095 scale
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cittecla | 3:94026b29e994 | 1 | #include "main.h" |
cittecla | 2:72886e996098 | 2 | |
itslinear | 17:bbafd216e059 | 3 | |
cittecla | 42:ba59ed6a2a06 | 4 | int state = 51; |
cittecla | 41:f054a83f9556 | 5 | int oldState; |
cittecla | 2:72886e996098 | 6 | |
cittecla | 2:72886e996098 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
aeschsim | 40:b5e533e1e033 | 8 | |
aeschsim | 40:b5e533e1e033 | 9 | /* PWM Test Tool */ |
aeschsim | 40:b5e533e1e033 | 10 | int channel; |
aeschsim | 40:b5e533e1e033 | 11 | int dutyCycle; |
cittecla | 2:72886e996098 | 12 | |
cittecla | 2:72886e996098 | 13 | int main() |
cittecla | 2:72886e996098 | 14 | { |
cittecla | 2:72886e996098 | 15 | pc.baud(460800); |
cittecla | 2:72886e996098 | 16 | printf("start...\r\n"); |
cittecla | 2:72886e996098 | 17 | |
aeschsim | 34:9d6dd3a12641 | 18 | while(1) { |
cittecla | 41:f054a83f9556 | 19 | if(state != oldState) { |
aeschsim | 34:9d6dd3a12641 | 20 | printf("state: %d\r\n",state); |
cittecla | 41:f054a83f9556 | 21 | oldState = state; |
aeschsim | 34:9d6dd3a12641 | 22 | } |
aeschsim | 34:9d6dd3a12641 | 23 | switch (state) { |
aeschsim | 34:9d6dd3a12641 | 24 | case 0: |
aeschsim | 34:9d6dd3a12641 | 25 | printf("Hello World"); |
aeschsim | 40:b5e533e1e033 | 26 | state = 47; |
aeschsim | 34:9d6dd3a12641 | 27 | break; |
aeschsim | 34:9d6dd3a12641 | 28 | case 1: |
aeschsim | 34:9d6dd3a12641 | 29 | break; |
aeschsim | 34:9d6dd3a12641 | 30 | case 2: |
aeschsim | 34:9d6dd3a12641 | 31 | break; |
aeschsim | 34:9d6dd3a12641 | 32 | case 3: |
aeschsim | 34:9d6dd3a12641 | 33 | break; |
cittecla | 2:72886e996098 | 34 | |
aeschsim | 34:9d6dd3a12641 | 35 | case 10: |
aeschsim | 34:9d6dd3a12641 | 36 | break; |
aeschsim | 34:9d6dd3a12641 | 37 | case 11: |
aeschsim | 34:9d6dd3a12641 | 38 | break; |
cittecla | 2:72886e996098 | 39 | |
aeschsim | 34:9d6dd3a12641 | 40 | case 15: |
aeschsim | 34:9d6dd3a12641 | 41 | break; |
aeschsim | 34:9d6dd3a12641 | 42 | case 16: |
aeschsim | 34:9d6dd3a12641 | 43 | break; |
aeschsim | 34:9d6dd3a12641 | 44 | case 17: |
aeschsim | 34:9d6dd3a12641 | 45 | break; |
aeschsim | 34:9d6dd3a12641 | 46 | |
aeschsim | 34:9d6dd3a12641 | 47 | case 25: |
aeschsim | 34:9d6dd3a12641 | 48 | break; |
aeschsim | 34:9d6dd3a12641 | 49 | case 26: |
aeschsim | 34:9d6dd3a12641 | 50 | break; |
aeschsim | 34:9d6dd3a12641 | 51 | case 27: |
aeschsim | 34:9d6dd3a12641 | 52 | break; |
aeschsim | 34:9d6dd3a12641 | 53 | case 28: |
aeschsim | 34:9d6dd3a12641 | 54 | break; |
cittecla | 2:72886e996098 | 55 | |
cittecla | 2:72886e996098 | 56 | |
aeschsim | 34:9d6dd3a12641 | 57 | case 35: |
aeschsim | 34:9d6dd3a12641 | 58 | break; |
aeschsim | 34:9d6dd3a12641 | 59 | case 36: |
aeschsim | 34:9d6dd3a12641 | 60 | break; |
aeschsim | 34:9d6dd3a12641 | 61 | case 37: |
aeschsim | 34:9d6dd3a12641 | 62 | break; |
aeschsim | 34:9d6dd3a12641 | 63 | case 38: |
aeschsim | 34:9d6dd3a12641 | 64 | break; |
aeschsim | 27:bf0577ecfa6e | 65 | |
aeschsim | 40:b5e533e1e033 | 66 | /**************************************************************/ |
aeschsim | 40:b5e533e1e033 | 67 | /* Test Zone */ |
aeschsim | 40:b5e533e1e033 | 68 | |
aeschsim | 40:b5e533e1e033 | 69 | /* Time test tool: set Time */ |
aeschsim | 34:9d6dd3a12641 | 70 | case 45: |
aeschsim | 34:9d6dd3a12641 | 71 | s_time time; |
aeschsim | 34:9d6dd3a12641 | 72 | time.second = 30; |
aeschsim | 34:9d6dd3a12641 | 73 | time.minute = 53; |
aeschsim | 34:9d6dd3a12641 | 74 | time.hour = 12; |
aeschsim | 34:9d6dd3a12641 | 75 | time.day = 27; |
aeschsim | 34:9d6dd3a12641 | 76 | time.weekday = 2; |
aeschsim | 34:9d6dd3a12641 | 77 | time.month = 3; |
aeschsim | 34:9d6dd3a12641 | 78 | time.year = 18; |
aeschsim | 34:9d6dd3a12641 | 79 | pc.printf("set now time\r\n"); |
aeschsim | 34:9d6dd3a12641 | 80 | setTime(&time); |
aeschsim | 35:a9bf045dc014 | 81 | pc.printf("read time: %02d:%02d:%02d, %02d.%02d.20%02d, weekday: %d\r\n",time.hour, time.minute, time.second, time.day, time.month, time.year, time.weekday); |
aeschsim | 40:b5e533e1e033 | 82 | state = 47; |
aeschsim | 34:9d6dd3a12641 | 83 | pc.printf("change state to: %d\r\n",state); |
aeschsim | 34:9d6dd3a12641 | 84 | break; |
aeschsim | 40:b5e533e1e033 | 85 | |
aeschsim | 40:b5e533e1e033 | 86 | /* Time test tool: get Time */ |
aeschsim | 34:9d6dd3a12641 | 87 | case 46: |
aeschsim | 34:9d6dd3a12641 | 88 | wait(5); |
aeschsim | 34:9d6dd3a12641 | 89 | time = getTime(); |
aeschsim | 35:a9bf045dc014 | 90 | pc.printf("read time: %02d:%02d:%02d, %02d.%02d.20%02d, weekday: %d\r\n",time.hour, time.minute, time.second, time.day, time.month, time.year, time.weekday); |
aeschsim | 40:b5e533e1e033 | 91 | state = 47; |
aeschsim | 40:b5e533e1e033 | 92 | break; |
aeschsim | 40:b5e533e1e033 | 93 | |
aeschsim | 40:b5e533e1e033 | 94 | /* Console State Switch */ |
aeschsim | 40:b5e533e1e033 | 95 | case 47: |
cittecla | 42:ba59ed6a2a06 | 96 | pc.printf("\n\rState Switch: Enter next State: \n\r"); |
cittecla | 42:ba59ed6a2a06 | 97 | pc.printf("45\tset Time\n\r46\tread Time\n\r47\tState Switch\n\r48\tServo Board Test Tool\n\r49\tenable servo output\n\r50\tdisable servo output\n\r"); |
aeschsim | 40:b5e533e1e033 | 98 | pc.scanf("%d", &state); |
aeschsim | 40:b5e533e1e033 | 99 | pc.printf("Switch to State %d\n\r",state); |
aeschsim | 40:b5e533e1e033 | 100 | fflush(stdin); |
aeschsim | 34:9d6dd3a12641 | 101 | break; |
aeschsim | 40:b5e533e1e033 | 102 | |
aeschsim | 40:b5e533e1e033 | 103 | /* Servo-Board Test Tool */ |
aeschsim | 34:9d6dd3a12641 | 104 | case 48: |
aeschsim | 46:cdc24a24e4e3 | 105 | pc.printf("\n\r\n\rServo-Board Test Tool\n\rEnter Channel Number and then Duty Cycle\n\r"); |
aeschsim | 46:cdc24a24e4e3 | 106 | pc.printf("for exit, enter Channel > 15\n\r"); |
aeschsim | 40:b5e533e1e033 | 107 | channel = 0; |
aeschsim | 40:b5e533e1e033 | 108 | while (channel < 16) { |
aeschsim | 40:b5e533e1e033 | 109 | pc.printf("Channel Number: "); |
aeschsim | 40:b5e533e1e033 | 110 | pc.scanf("%d", &channel); |
aeschsim | 46:cdc24a24e4e3 | 111 | pc.printf("\r\nchannel: %d\n\rDuty Cycle 0..4095: ",channel); |
aeschsim | 40:b5e533e1e033 | 112 | pc.scanf("%d", &dutyCycle); |
aeschsim | 46:cdc24a24e4e3 | 113 | pc.printf("\n\r%d\n\r",dutyCycle); |
aeschsim | 46:cdc24a24e4e3 | 114 | setPWM((char)channel, (int)dutyCycle); |
aeschsim | 40:b5e533e1e033 | 115 | fflush(stdin); |
aeschsim | 40:b5e533e1e033 | 116 | } |
aeschsim | 40:b5e533e1e033 | 117 | pc.printf("leave Servo-Board Test Tool\n\r"); |
aeschsim | 40:b5e533e1e033 | 118 | state = 47; |
aeschsim | 40:b5e533e1e033 | 119 | break; |
aeschsim | 40:b5e533e1e033 | 120 | |
aeschsim | 40:b5e533e1e033 | 121 | case 49: |
cittecla | 42:ba59ed6a2a06 | 122 | enableOutput(); |
cittecla | 42:ba59ed6a2a06 | 123 | pc.printf("Servo output enabled\r\n\n"); |
aeschsim | 40:b5e533e1e033 | 124 | state = 47; |
aeschsim | 34:9d6dd3a12641 | 125 | break; |
cittecla | 2:72886e996098 | 126 | |
aeschsim | 34:9d6dd3a12641 | 127 | case 50: |
cittecla | 42:ba59ed6a2a06 | 128 | disableOutput(); |
cittecla | 42:ba59ed6a2a06 | 129 | pc.printf("Servo output disabled\r\n\n"); |
aeschsim | 40:b5e533e1e033 | 130 | state = 47; |
aeschsim | 40:b5e533e1e033 | 131 | break; |
aeschsim | 40:b5e533e1e033 | 132 | |
cittecla | 42:ba59ed6a2a06 | 133 | case 51: |
cittecla | 42:ba59ed6a2a06 | 134 | pc.printf("Init PWM\r\n"); |
aeschsim | 46:cdc24a24e4e3 | 135 | initPWM(50); |
cittecla | 42:ba59ed6a2a06 | 136 | enableOutput(); |
cittecla | 42:ba59ed6a2a06 | 137 | state = 47; |
cittecla | 42:ba59ed6a2a06 | 138 | break; |
aeschsim | 46:cdc24a24e4e3 | 139 | |
aeschsim | 40:b5e533e1e033 | 140 | default: |
aeschsim | 40:b5e533e1e033 | 141 | state = 47; /* Go to State Switch */ |
aeschsim | 34:9d6dd3a12641 | 142 | break; |
aeschsim | 34:9d6dd3a12641 | 143 | } |
cittecla | 2:72886e996098 | 144 | } |
aeschsim | 34:9d6dd3a12641 | 145 | pc.printf("exit while 1 loop"); |
cittecla | 2:72886e996098 | 146 | } |