Motion controll board test program
Dependencies: Motor mbed eeprom
main.cpp@1:5a5abae3748b, 2016-03-26 (annotated)
- Committer:
- sunarin
- Date:
- Sat Mar 26 07:50:05 2016 +0000
- Revision:
- 1:5a5abae3748b
- Parent:
- 0:be4a5e3ebb41
motor active
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ParinyaT | 0:be4a5e3ebb41 | 1 | #include "mbed.h" |
ParinyaT | 0:be4a5e3ebb41 | 2 | #include "Motor.h" |
sunarin | 1:5a5abae3748b | 3 | #include "pinconfig.h" |
sunarin | 1:5a5abae3748b | 4 | #include "eeprom.h" |
ParinyaT | 0:be4a5e3ebb41 | 5 | |
sunarin | 1:5a5abae3748b | 6 | Serial rd(D1,D0); |
sunarin | 1:5a5abae3748b | 7 | Serial pc(D8,D2); |
sunarin | 1:5a5abae3748b | 8 | AnalogIn Ain1(PC_2); |
sunarin | 1:5a5abae3748b | 9 | AnalogIn Ain2(PC_3); |
sunarin | 1:5a5abae3748b | 10 | DigitalIn enable(PB_7); |
sunarin | 1:5a5abae3748b | 11 | DigitalIn enable1(PC_13); |
sunarin | 1:5a5abae3748b | 12 | EEPROM memory(PB_4,PA_8,0); |
sunarin | 1:5a5abae3748b | 13 | DigitalOut dout(LED1); |
sunarin | 1:5a5abae3748b | 14 | |
sunarin | 1:5a5abae3748b | 15 | int main(void) |
ParinyaT | 0:be4a5e3ebb41 | 16 | { |
sunarin | 1:5a5abae3748b | 17 | Motor Upper1(PWM_LU,A_LU,B_LU ); |
sunarin | 1:5a5abae3748b | 18 | Motor Upper2(PWM_LL,A_LL,B_LL ); |
sunarin | 1:5a5abae3748b | 19 | Upper1.period(0.00001); |
sunarin | 1:5a5abae3748b | 20 | Upper2.period(0.00001); |
sunarin | 1:5a5abae3748b | 21 | uint8_t data; |
sunarin | 1:5a5abae3748b | 22 | // uint8_t sw= Switch.read(); |
sunarin | 1:5a5abae3748b | 23 | |
sunarin | 1:5a5abae3748b | 24 | float x,j; |
sunarin | 1:5a5abae3748b | 25 | float y,j1; |
sunarin | 1:5a5abae3748b | 26 | int k; |
sunarin | 1:5a5abae3748b | 27 | rd.printf("Hello World !\n"); |
sunarin | 1:5a5abae3748b | 28 | |
sunarin | 1:5a5abae3748b | 29 | while(1) { |
sunarin | 1:5a5abae3748b | 30 | data = pc.getc(); |
sunarin | 1:5a5abae3748b | 31 | rd.printf("%c",data); |
sunarin | 1:5a5abae3748b | 32 | rd.printf("\n"); |
sunarin | 1:5a5abae3748b | 33 | wait_ms(100); |
sunarin | 1:5a5abae3748b | 34 | |
sunarin | 1:5a5abae3748b | 35 | switch(data) { |
sunarin | 1:5a5abae3748b | 36 | |
sunarin | 1:5a5abae3748b | 37 | case'u': |
sunarin | 1:5a5abae3748b | 38 | pc.printf("Motor up left\n"); |
sunarin | 1:5a5abae3748b | 39 | Upper1.speed(1); |
sunarin | 1:5a5abae3748b | 40 | break; |
sunarin | 1:5a5abae3748b | 41 | |
sunarin | 1:5a5abae3748b | 42 | case'd': |
sunarin | 1:5a5abae3748b | 43 | Upper1.speed(-1); |
sunarin | 1:5a5abae3748b | 44 | pc.printf("Motor down left\n"); |
sunarin | 1:5a5abae3748b | 45 | /* |
sunarin | 1:5a5abae3748b | 46 | if(enable==1) { |
sunarin | 1:5a5abae3748b | 47 | Upper1.speed(0); |
sunarin | 1:5a5abae3748b | 48 | //printf("stop\n"); |
sunarin | 1:5a5abae3748b | 49 | } else if(enable==0) { |
sunarin | 1:5a5abae3748b | 50 | Upper1.speed(-1); |
sunarin | 1:5a5abae3748b | 51 | //printf("down left\n"); |
sunarin | 1:5a5abae3748b | 52 | } |
sunarin | 1:5a5abae3748b | 53 | */ |
sunarin | 1:5a5abae3748b | 54 | break; |
sunarin | 1:5a5abae3748b | 55 | |
sunarin | 1:5a5abae3748b | 56 | case'l': |
sunarin | 1:5a5abae3748b | 57 | pc.printf("Motor up right\n"); |
sunarin | 1:5a5abae3748b | 58 | Upper2.speed(1); |
sunarin | 1:5a5abae3748b | 59 | break; |
sunarin | 1:5a5abae3748b | 60 | |
sunarin | 1:5a5abae3748b | 61 | case'k': |
sunarin | 1:5a5abae3748b | 62 | Upper2.speed(-1); |
sunarin | 1:5a5abae3748b | 63 | pc.printf("Motor down right\n"); |
sunarin | 1:5a5abae3748b | 64 | /* |
sunarin | 1:5a5abae3748b | 65 | |
sunarin | 1:5a5abae3748b | 66 | if(enable1==1) { |
sunarin | 1:5a5abae3748b | 67 | Upper2.speed(0); |
sunarin | 1:5a5abae3748b | 68 | //printf("stop\n"); |
sunarin | 1:5a5abae3748b | 69 | } else if(enable1==0) { |
sunarin | 1:5a5abae3748b | 70 | Upper2.speed(-1); |
sunarin | 1:5a5abae3748b | 71 | //printf("down right\n"); |
sunarin | 1:5a5abae3748b | 72 | } |
sunarin | 1:5a5abae3748b | 73 | */ |
sunarin | 1:5a5abae3748b | 74 | break; |
sunarin | 1:5a5abae3748b | 75 | |
sunarin | 1:5a5abae3748b | 76 | case's': |
sunarin | 1:5a5abae3748b | 77 | //printf("Motor stop\n"); |
sunarin | 1:5a5abae3748b | 78 | pc.printf("Motor stop\n"); |
sunarin | 1:5a5abae3748b | 79 | Upper1.speed(0); |
sunarin | 1:5a5abae3748b | 80 | Upper2.speed(0); |
sunarin | 1:5a5abae3748b | 81 | break; |
sunarin | 1:5a5abae3748b | 82 | |
sunarin | 1:5a5abae3748b | 83 | case'w': |
sunarin | 1:5a5abae3748b | 84 | j = (Ain1.read()*3.3); |
sunarin | 1:5a5abae3748b | 85 | pc.printf("memory = %3.3f\n",j); |
sunarin | 1:5a5abae3748b | 86 | memory.write(14,j); |
sunarin | 1:5a5abae3748b | 87 | wait_ms(1); |
sunarin | 1:5a5abae3748b | 88 | j1 = (Ain2.read()*3.3); |
sunarin | 1:5a5abae3748b | 89 | pc.printf("memory = %3.3f\n",j1); |
sunarin | 1:5a5abae3748b | 90 | memory.write(11,j1); |
sunarin | 1:5a5abae3748b | 91 | wait_ms(1); |
sunarin | 1:5a5abae3748b | 92 | break; |
sunarin | 1:5a5abae3748b | 93 | |
sunarin | 1:5a5abae3748b | 94 | case'e': |
sunarin | 1:5a5abae3748b | 95 | |
sunarin | 1:5a5abae3748b | 96 | memory.read(14,x); |
sunarin | 1:5a5abae3748b | 97 | wait_ms(1); |
sunarin | 1:5a5abae3748b | 98 | pc.printf("display = %3.3f\n",j); |
sunarin | 1:5a5abae3748b | 99 | memory.read(11,y); |
sunarin | 1:5a5abae3748b | 100 | wait_ms(1); |
sunarin | 1:5a5abae3748b | 101 | pc.printf("diplay = %3.3f\n",j1); |
sunarin | 1:5a5abae3748b | 102 | break; |
sunarin | 1:5a5abae3748b | 103 | } |
ParinyaT | 0:be4a5e3ebb41 | 104 | } |
sunarin | 1:5a5abae3748b | 105 | } |