a
Dependencies: mbed
main.cpp@0:f5cd2be82e8e, 2015-01-28 (annotated)
- Committer:
- bulmenwt
- Date:
- Wed Jan 28 07:50:37 2015 +0000
- Revision:
- 0:f5cd2be82e8e
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bulmenwt | 0:f5cd2be82e8e | 1 | #include "mbed.h" |
bulmenwt | 0:f5cd2be82e8e | 2 | |
bulmenwt | 0:f5cd2be82e8e | 3 | BusOut myled_port(p21,p22,p23,p24,LED4,LED3,LED2,LED1,p25); |
bulmenwt | 0:f5cd2be82e8e | 4 | // LSB MSB |
bulmenwt | 0:f5cd2be82e8e | 5 | // A = p21 B = p22 C = p23 D = p24 |
bulmenwt | 0:f5cd2be82e8e | 6 | |
bulmenwt | 0:f5cd2be82e8e | 7 | // myled_port = 0x p21 p22 p23 p24 LED4 LED3 LED2 LED1 p25; |
bulmenwt | 0:f5cd2be82e8e | 8 | // A B C D Enable |
bulmenwt | 0:f5cd2be82e8e | 9 | // LSB MSB |
bulmenwt | 0:f5cd2be82e8e | 10 | //myled_port = 0x111; |
bulmenwt | 0:f5cd2be82e8e | 11 | // ELP |
bulmenwt | 0:f5cd2be82e8e | 12 | /* |
bulmenwt | 0:f5cd2be82e8e | 13 | E....Enable für den Schrittmotor |
bulmenwt | 0:f5cd2be82e8e | 14 | ACHTUNG E=0 ....aktiv (invertiert !!) |
bulmenwt | 0:f5cd2be82e8e | 15 | |
bulmenwt | 0:f5cd2be82e8e | 16 | |
bulmenwt | 0:f5cd2be82e8e | 17 | Wave-Drive-Betrieb (Wellenschritt-Modus)rechts |
bulmenwt | 0:f5cd2be82e8e | 18 | A B C D E |
bulmenwt | 0:f5cd2be82e8e | 19 | 1 0 0 0 0 |
bulmenwt | 0:f5cd2be82e8e | 20 | 0 1 0 0 0 |
bulmenwt | 0:f5cd2be82e8e | 21 | 0 0 1 0 0 |
bulmenwt | 0:f5cd2be82e8e | 22 | 0 0 0 1 0 |
bulmenwt | 0:f5cd2be82e8e | 23 | ---------------------------------- |
bulmenwt | 0:f5cd2be82e8e | 24 | Wave-Drive-Betrieb (Wellenschritt-Modus)links |
bulmenwt | 0:f5cd2be82e8e | 25 | A B C D E |
bulmenwt | 0:f5cd2be82e8e | 26 | 0 0 0 1 0 |
bulmenwt | 0:f5cd2be82e8e | 27 | 0 0 1 0 0 |
bulmenwt | 0:f5cd2be82e8e | 28 | 0 1 0 0 0 |
bulmenwt | 0:f5cd2be82e8e | 29 | 1 0 0 0 0 |
bulmenwt | 0:f5cd2be82e8e | 30 | ---------------------------------- |
bulmenwt | 0:f5cd2be82e8e | 31 | Vollschritt rechts |
bulmenwt | 0:f5cd2be82e8e | 32 | 1 2 4 8 |
bulmenwt | 0:f5cd2be82e8e | 33 | A B C D E |
bulmenwt | 0:f5cd2be82e8e | 34 | 1 1 0 0 0 = 0x3 |
bulmenwt | 0:f5cd2be82e8e | 35 | 0 1 1 0 0 = 0x6 |
bulmenwt | 0:f5cd2be82e8e | 36 | 0 0 1 1 0 = 0xC |
bulmenwt | 0:f5cd2be82e8e | 37 | 1 0 0 1 0 = 0x9 |
bulmenwt | 0:f5cd2be82e8e | 38 | ------------------------------------ |
bulmenwt | 0:f5cd2be82e8e | 39 | Halbschritt rechts |
bulmenwt | 0:f5cd2be82e8e | 40 | 1 2 4 8 |
bulmenwt | 0:f5cd2be82e8e | 41 | A B C D E |
bulmenwt | 0:f5cd2be82e8e | 42 | 1 0 0 0 0 = 0x1 |
bulmenwt | 0:f5cd2be82e8e | 43 | 1 1 0 0 0 = 0x3 |
bulmenwt | 0:f5cd2be82e8e | 44 | 0 1 0 0 0 = 0x2 |
bulmenwt | 0:f5cd2be82e8e | 45 | 0 1 1 0 0 = 0x6 |
bulmenwt | 0:f5cd2be82e8e | 46 | 0 0 1 0 0 = 0x4 |
bulmenwt | 0:f5cd2be82e8e | 47 | 0 0 1 1 0 = 0xC |
bulmenwt | 0:f5cd2be82e8e | 48 | 0 0 0 1 0 = 0x8 |
bulmenwt | 0:f5cd2be82e8e | 49 | 1 0 0 1 0 = 0x9 |
bulmenwt | 0:f5cd2be82e8e | 50 | |
bulmenwt | 0:f5cd2be82e8e | 51 | */ |
bulmenwt | 0:f5cd2be82e8e | 52 | |
bulmenwt | 0:f5cd2be82e8e | 53 | Serial pc(USBTX, USBRX); // tx, rx |
bulmenwt | 0:f5cd2be82e8e | 54 | char ch; |
bulmenwt | 0:f5cd2be82e8e | 55 | |
bulmenwt | 0:f5cd2be82e8e | 56 | |
bulmenwt | 0:f5cd2be82e8e | 57 | int zeit=1; // sec |
bulmenwt | 0:f5cd2be82e8e | 58 | int zahl,schritte=5; |
bulmenwt | 0:f5cd2be82e8e | 59 | |
bulmenwt | 0:f5cd2be82e8e | 60 | |
bulmenwt | 0:f5cd2be82e8e | 61 | |
bulmenwt | 0:f5cd2be82e8e | 62 | |
bulmenwt | 0:f5cd2be82e8e | 63 | int main() { |
bulmenwt | 0:f5cd2be82e8e | 64 | pc.printf("Schrittmotor steuern mittels Raspberry PI!\r\n"); |
bulmenwt | 0:f5cd2be82e8e | 65 | pc.printf("DI Franz Wolf (WF)\r\n"); |
bulmenwt | 0:f5cd2be82e8e | 66 | pc.printf("Wave-Drive-Betrieb rechts: Dr\x81cken Sie 1 <n>\r\n"); |
bulmenwt | 0:f5cd2be82e8e | 67 | pc.printf("Wave-Drive-Betrieb links : Dr\x81cken Sie 2 <n>\r\n"); |
bulmenwt | 0:f5cd2be82e8e | 68 | pc.printf("Vollschritte-Betrieb: Dr\x81cken Sie 3 <n>\r\n"); |
bulmenwt | 0:f5cd2be82e8e | 69 | pc.printf("Halbschritt-Betrieb: Dr\x81cken Sie 4 <n>\r\n"); |
bulmenwt | 0:f5cd2be82e8e | 70 | |
bulmenwt | 0:f5cd2be82e8e | 71 | // printf("Die Umlaute: \x81 \x84 \x94 \x8E \x99 \x9A \xE1");//ü ä ö Ä Ö Ü ß |
bulmenwt | 0:f5cd2be82e8e | 72 | |
bulmenwt | 0:f5cd2be82e8e | 73 | |
bulmenwt | 0:f5cd2be82e8e | 74 | |
bulmenwt | 0:f5cd2be82e8e | 75 | while(1) { |
bulmenwt | 0:f5cd2be82e8e | 76 | |
bulmenwt | 0:f5cd2be82e8e | 77 | ch = pc.getc(); |
bulmenwt | 0:f5cd2be82e8e | 78 | |
bulmenwt | 0:f5cd2be82e8e | 79 | switch (ch) { |
bulmenwt | 0:f5cd2be82e8e | 80 | case '1': //Wave-Drive-Betrieb (Wellenschritt-Modus)rechts |
bulmenwt | 0:f5cd2be82e8e | 81 | for(zahl=1; zahl<=schritte; zahl++) |
bulmenwt | 0:f5cd2be82e8e | 82 | { |
bulmenwt | 0:f5cd2be82e8e | 83 | myled_port = 0x011; |
bulmenwt | 0:f5cd2be82e8e | 84 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 85 | myled_port = 0x012; |
bulmenwt | 0:f5cd2be82e8e | 86 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 87 | myled_port = 0x004; |
bulmenwt | 0:f5cd2be82e8e | 88 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 89 | myled_port = 0x008; |
bulmenwt | 0:f5cd2be82e8e | 90 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 91 | } |
bulmenwt | 0:f5cd2be82e8e | 92 | break; |
bulmenwt | 0:f5cd2be82e8e | 93 | |
bulmenwt | 0:f5cd2be82e8e | 94 | case '2': //Wave-Drive-Betrieb (Wellenschritt-Modus)links |
bulmenwt | 0:f5cd2be82e8e | 95 | for(zahl=1; zahl<=schritte; zahl++) |
bulmenwt | 0:f5cd2be82e8e | 96 | { |
bulmenwt | 0:f5cd2be82e8e | 97 | myled_port = 0x018; |
bulmenwt | 0:f5cd2be82e8e | 98 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 99 | myled_port = 0x014; |
bulmenwt | 0:f5cd2be82e8e | 100 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 101 | myled_port = 0x002; |
bulmenwt | 0:f5cd2be82e8e | 102 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 103 | myled_port = 0x001; |
bulmenwt | 0:f5cd2be82e8e | 104 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 105 | } |
bulmenwt | 0:f5cd2be82e8e | 106 | break; |
bulmenwt | 0:f5cd2be82e8e | 107 | |
bulmenwt | 0:f5cd2be82e8e | 108 | case '3': //Wave-Drive-Betrieb (Wellenschritt-Modus)links |
bulmenwt | 0:f5cd2be82e8e | 109 | for(zahl=1; zahl<=schritte; zahl++) |
bulmenwt | 0:f5cd2be82e8e | 110 | { |
bulmenwt | 0:f5cd2be82e8e | 111 | myled_port = 0x013; |
bulmenwt | 0:f5cd2be82e8e | 112 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 113 | myled_port = 0x016; |
bulmenwt | 0:f5cd2be82e8e | 114 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 115 | myled_port = 0x00C; |
bulmenwt | 0:f5cd2be82e8e | 116 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 117 | myled_port = 0x009; |
bulmenwt | 0:f5cd2be82e8e | 118 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 119 | } |
bulmenwt | 0:f5cd2be82e8e | 120 | break; |
bulmenwt | 0:f5cd2be82e8e | 121 | |
bulmenwt | 0:f5cd2be82e8e | 122 | case '4': //Wave-Drive-Betrieb (Wellenschritt-Modus)links |
bulmenwt | 0:f5cd2be82e8e | 123 | for(zahl=1; zahl<=schritte; zahl++) |
bulmenwt | 0:f5cd2be82e8e | 124 | { |
bulmenwt | 0:f5cd2be82e8e | 125 | myled_port = 0x011; |
bulmenwt | 0:f5cd2be82e8e | 126 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 127 | myled_port = 0x013; |
bulmenwt | 0:f5cd2be82e8e | 128 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 129 | myled_port = 0x002; |
bulmenwt | 0:f5cd2be82e8e | 130 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 131 | myled_port = 0x006; |
bulmenwt | 0:f5cd2be82e8e | 132 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 133 | myled_port = 0x004; |
bulmenwt | 0:f5cd2be82e8e | 134 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 135 | myled_port = 0x01C; |
bulmenwt | 0:f5cd2be82e8e | 136 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 137 | myled_port = 0x018; |
bulmenwt | 0:f5cd2be82e8e | 138 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 139 | myled_port = 0x009; |
bulmenwt | 0:f5cd2be82e8e | 140 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 141 | } |
bulmenwt | 0:f5cd2be82e8e | 142 | break; |
bulmenwt | 0:f5cd2be82e8e | 143 | |
bulmenwt | 0:f5cd2be82e8e | 144 | } |
bulmenwt | 0:f5cd2be82e8e | 145 | |
bulmenwt | 0:f5cd2be82e8e | 146 | |
bulmenwt | 0:f5cd2be82e8e | 147 | |
bulmenwt | 0:f5cd2be82e8e | 148 | |
bulmenwt | 0:f5cd2be82e8e | 149 | /* |
bulmenwt | 0:f5cd2be82e8e | 150 | |
bulmenwt | 0:f5cd2be82e8e | 151 | if (ch == 'a') { // Motor aus |
bulmenwt | 0:f5cd2be82e8e | 152 | |
bulmenwt | 0:f5cd2be82e8e | 153 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 154 | myled_port = 0x111; |
bulmenwt | 0:f5cd2be82e8e | 155 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 156 | myled_port = 0x112; |
bulmenwt | 0:f5cd2be82e8e | 157 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 158 | myled_port = 0x104; |
bulmenwt | 0:f5cd2be82e8e | 159 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 160 | myled_port = 0x108; |
bulmenwt | 0:f5cd2be82e8e | 161 | |
bulmenwt | 0:f5cd2be82e8e | 162 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 163 | myled_port = 0x118; |
bulmenwt | 0:f5cd2be82e8e | 164 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 165 | myled_port = 0x114; |
bulmenwt | 0:f5cd2be82e8e | 166 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 167 | myled_port = 0x102; |
bulmenwt | 0:f5cd2be82e8e | 168 | wait(zeit); |
bulmenwt | 0:f5cd2be82e8e | 169 | myled_port = 0x101; |
bulmenwt | 0:f5cd2be82e8e | 170 | */ |
bulmenwt | 0:f5cd2be82e8e | 171 | |
bulmenwt | 0:f5cd2be82e8e | 172 | } |
bulmenwt | 0:f5cd2be82e8e | 173 | } |