Saad Tayyab
/
takeover
aaaaaa
main.cpp@0:3849fc9c544a, 2018-05-02 (annotated)
- Committer:
- rottenegg
- Date:
- Wed May 02 11:30:19 2018 +0000
- Revision:
- 0:3849fc9c544a
aaaaaaaaa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rottenegg | 0:3849fc9c544a | 1 | #include "mbed.h" |
rottenegg | 0:3849fc9c544a | 2 | |
rottenegg | 0:3849fc9c544a | 3 | BusOut pins(p20,p19,p18,p17,p16,p15,p14,p13); |
rottenegg | 0:3849fc9c544a | 4 | Serial pc(USBTX,USBRX); |
rottenegg | 0:3849fc9c544a | 5 | DigitalOut j(p9); |
rottenegg | 0:3849fc9c544a | 6 | |
rottenegg | 0:3849fc9c544a | 7 | void jump(){ |
rottenegg | 0:3849fc9c544a | 8 | int stop = 0; |
rottenegg | 0:3849fc9c544a | 9 | char stopp; |
rottenegg | 0:3849fc9c544a | 10 | pc.printf("To jump press 1 to exit press 0") |
rottenegg | 0:3849fc9c544a | 11 | while (stop == 0){ |
rottenegg | 0:3849fc9c544a | 12 | char option = pc.getc |
rottenegg | 0:3849fc9c544a | 13 | if (option == 1) { |
rottenegg | 0:3849fc9c544a | 14 | j = 1; |
rottenegg | 0:3849fc9c544a | 15 | } |
rottenegg | 0:3849fc9c544a | 16 | else if (option == 0) { |
rottenegg | 0:3849fc9c544a | 17 | stop = 1; |
rottenegg | 0:3849fc9c544a | 18 | } |
rottenegg | 0:3849fc9c544a | 19 | else { |
rottenegg | 0:3849fc9c544a | 20 | j = 0; |
rottenegg | 0:3849fc9c544a | 21 | } |
rottenegg | 0:3849fc9c544a | 22 | } |
rottenegg | 0:3849fc9c544a | 23 | }; |
rottenegg | 0:3849fc9c544a | 24 | |
rottenegg | 0:3849fc9c544a | 25 | void nscan(){ |
rottenegg | 0:3849fc9c544a | 26 | pc.printf("Scanning... \n"); |
rottenegg | 0:3849fc9c544a | 27 | int isDone = 0; |
rottenegg | 0:3849fc9c544a | 28 | int counter = 0; |
rottenegg | 0:3849fc9c544a | 29 | while( isDone == 0 ) { |
rottenegg | 0:3849fc9c544a | 30 | pc.printf("scanning %d\n",counter); |
rottenegg | 0:3849fc9c544a | 31 | char stop; |
rottenegg | 0:3849fc9c544a | 32 | char stopp; |
rottenegg | 0:3849fc9c544a | 33 | stopp = pc.readable(); |
rottenegg | 0:3849fc9c544a | 34 | pins = counter; |
rottenegg | 0:3849fc9c544a | 35 | wait_ms(3000); |
rottenegg | 0:3849fc9c544a | 36 | stop = pc.readable(); |
rottenegg | 0:3849fc9c544a | 37 | if (stop == stopp){ |
rottenegg | 0:3849fc9c544a | 38 | } |
rottenegg | 0:3849fc9c544a | 39 | else { |
rottenegg | 0:3849fc9c544a | 40 | isDone = 1; |
rottenegg | 0:3849fc9c544a | 41 | } |
rottenegg | 0:3849fc9c544a | 42 | if (counter == 256) { |
rottenegg | 0:3849fc9c544a | 43 | isDone = 1; |
rottenegg | 0:3849fc9c544a | 44 | } |
rottenegg | 0:3849fc9c544a | 45 | counter++; |
rottenegg | 0:3849fc9c544a | 46 | } |
rottenegg | 0:3849fc9c544a | 47 | }; |
rottenegg | 0:3849fc9c544a | 48 | |
rottenegg | 0:3849fc9c544a | 49 | |
rottenegg | 0:3849fc9c544a | 50 | void scan() { |
rottenegg | 0:3849fc9c544a | 51 | pc.printf("Scanning... \n"); |
rottenegg | 0:3849fc9c544a | 52 | int isDone = 0; |
rottenegg | 0:3849fc9c544a | 53 | int counter = 127; |
rottenegg | 0:3849fc9c544a | 54 | int counter2 = 128; |
rottenegg | 0:3849fc9c544a | 55 | while( isDone == 0 ) { |
rottenegg | 0:3849fc9c544a | 56 | pc.printf("scanning %d and %d\n",counter,counter2); |
rottenegg | 0:3849fc9c544a | 57 | char stop; |
rottenegg | 0:3849fc9c544a | 58 | char stopp; |
rottenegg | 0:3849fc9c544a | 59 | stopp = pc.readable(); |
rottenegg | 0:3849fc9c544a | 60 | pins = counter; |
rottenegg | 0:3849fc9c544a | 61 | wait_ms(3000); |
rottenegg | 0:3849fc9c544a | 62 | pins = counter2; |
rottenegg | 0:3849fc9c544a | 63 | wait_ms(3000); |
rottenegg | 0:3849fc9c544a | 64 | stop = pc.readable(); |
rottenegg | 0:3849fc9c544a | 65 | if (stop == stopp){ |
rottenegg | 0:3849fc9c544a | 66 | } |
rottenegg | 0:3849fc9c544a | 67 | else { |
rottenegg | 0:3849fc9c544a | 68 | isDone = 1; |
rottenegg | 0:3849fc9c544a | 69 | } |
rottenegg | 0:3849fc9c544a | 70 | if (counter == 0) { |
rottenegg | 0:3849fc9c544a | 71 | isDone = 1; |
rottenegg | 0:3849fc9c544a | 72 | } |
rottenegg | 0:3849fc9c544a | 73 | counter--; |
rottenegg | 0:3849fc9c544a | 74 | counter2++; |
rottenegg | 0:3849fc9c544a | 75 | } |
rottenegg | 0:3849fc9c544a | 76 | }; |
rottenegg | 0:3849fc9c544a | 77 | |
rottenegg | 0:3849fc9c544a | 78 | void control() { |
rottenegg | 0:3849fc9c544a | 79 | pc.printf("Enter Control Number\n"); |
rottenegg | 0:3849fc9c544a | 80 | int in; |
rottenegg | 0:3849fc9c544a | 81 | pc.scanf("%d",&in); |
rottenegg | 0:3849fc9c544a | 82 | pins = in; |
rottenegg | 0:3849fc9c544a | 83 | |
rottenegg | 0:3849fc9c544a | 84 | |
rottenegg | 0:3849fc9c544a | 85 | } |
rottenegg | 0:3849fc9c544a | 86 | int main() { |
rottenegg | 0:3849fc9c544a | 87 | while(1) { |
rottenegg | 0:3849fc9c544a | 88 | pc.printf("Traxter Take Over Program Serial Terminal\n"); |
rottenegg | 0:3849fc9c544a | 89 | pc.printf("Enter Optimized Scan mode press 1\n"); |
rottenegg | 0:3849fc9c544a | 90 | pc.printf("Enter Control Mode Press 2\n"); |
rottenegg | 0:3849fc9c544a | 91 | pc.printf("Enter Normal Scan press 3\n"); |
rottenegg | 0:3849fc9c544a | 92 | pc.printf("Enter Jump Mode Enter 4\n"); |
rottenegg | 0:3849fc9c544a | 93 | char ans = pc.getc(); |
rottenegg | 0:3849fc9c544a | 94 | if (ans == '1'){ |
rottenegg | 0:3849fc9c544a | 95 | scan(); |
rottenegg | 0:3849fc9c544a | 96 | } |
rottenegg | 0:3849fc9c544a | 97 | else if (ans == '3'){ |
rottenegg | 0:3849fc9c544a | 98 | nscan(); |
rottenegg | 0:3849fc9c544a | 99 | } |
rottenegg | 0:3849fc9c544a | 100 | else if (ans == '2'){ |
rottenegg | 0:3849fc9c544a | 101 | control(); |
rottenegg | 0:3849fc9c544a | 102 | } |
rottenegg | 0:3849fc9c544a | 103 | else if (ans == '4'){ |
rottenegg | 0:3849fc9c544a | 104 | jump(); |
rottenegg | 0:3849fc9c544a | 105 | } |
rottenegg | 0:3849fc9c544a | 106 | |
rottenegg | 0:3849fc9c544a | 107 | else { |
rottenegg | 0:3849fc9c544a | 108 | pc.printf("Invalid Fool\n"); |
rottenegg | 0:3849fc9c544a | 109 | } |
rottenegg | 0:3849fc9c544a | 110 | } |
rottenegg | 0:3849fc9c544a | 111 | } |