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.
main.cpp@6:44d1079f076c, 2015-02-18 (annotated)
- Committer:
- bbbobbbieo
- Date:
- Wed Feb 18 20:51:28 2015 +0000
- Revision:
- 6:44d1079f076c
- Parent:
- 5:e7e4f1967fb8
- Child:
- 7:455e7dd338ee
servos work with pushbutton; rear motors are dumb;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bbbobbbieo | 3:c7caa058fc50 | 1 | //#include "mbed.h" |
bbbobbbieo | 1:21d40d90b2f0 | 2 | #include "TFC.h" |
bbbobbbieo | 0:d57117b2188d | 3 | |
bbbobbbieo | 0:d57117b2188d | 4 | DigitalOut myled(LED1); |
bbbobbbieo | 0:d57117b2188d | 5 | |
bbbobbbieo | 1:21d40d90b2f0 | 6 | int main() |
bbbobbbieo | 1:21d40d90b2f0 | 7 | { |
bbbobbbieo | 2:d8a51492b646 | 8 | TFC_Init(); |
bbbobbbieo | 2:d8a51492b646 | 9 | |
bbbobbbieo | 4:7584ff0426f1 | 10 | float current_servo_position = 0; |
bbbobbbieo | 6:44d1079f076c | 11 | float current_left_motor_speed = 0; |
bbbobbbieo | 6:44d1079f076c | 12 | float current_right_motor_speed = 0; |
bbbobbbieo | 6:44d1079f076c | 13 | bool rear_motor_enable_flag = true; |
bbbobbbieo | 4:7584ff0426f1 | 14 | |
bbbobbbieo | 1:21d40d90b2f0 | 15 | while(1) |
bbbobbbieo | 1:21d40d90b2f0 | 16 | { |
bbbobbbieo | 2:d8a51492b646 | 17 | |
bbbobbbieo | 3:c7caa058fc50 | 18 | if (TFC_ReadPushButton(0) != 0 ) |
bbbobbbieo | 3:c7caa058fc50 | 19 | { |
bbbobbbieo | 3:c7caa058fc50 | 20 | TFC_BAT_LED0_ON; |
bbbobbbieo | 6:44d1079f076c | 21 | wait(0.004); |
bbbobbbieo | 3:c7caa058fc50 | 22 | TFC_BAT_LED0_OFF; |
bbbobbbieo | 6:44d1079f076c | 23 | wait(0.004); |
bbbobbbieo | 4:7584ff0426f1 | 24 | |
bbbobbbieo | 6:44d1079f076c | 25 | current_servo_position = current_servo_position-.005; |
bbbobbbieo | 6:44d1079f076c | 26 | if(current_servo_position <= -0.4) |
bbbobbbieo | 6:44d1079f076c | 27 | current_servo_position = -0.4; |
bbbobbbieo | 5:e7e4f1967fb8 | 28 | TFC_SetServo(0, current_servo_position); |
bbbobbbieo | 3:c7caa058fc50 | 29 | } |
bbbobbbieo | 4:7584ff0426f1 | 30 | |
bbbobbbieo | 3:c7caa058fc50 | 31 | else |
bbbobbbieo | 3:c7caa058fc50 | 32 | { |
bbbobbbieo | 3:c7caa058fc50 | 33 | TFC_BAT_LED0_ON; |
bbbobbbieo | 3:c7caa058fc50 | 34 | } |
bbbobbbieo | 4:7584ff0426f1 | 35 | |
bbbobbbieo | 4:7584ff0426f1 | 36 | if (TFC_ReadPushButton(1) != 0 ) |
bbbobbbieo | 4:7584ff0426f1 | 37 | { |
bbbobbbieo | 4:7584ff0426f1 | 38 | TFC_BAT_LED1_ON; |
bbbobbbieo | 6:44d1079f076c | 39 | wait(0.004); |
bbbobbbieo | 4:7584ff0426f1 | 40 | TFC_BAT_LED1_OFF; |
bbbobbbieo | 6:44d1079f076c | 41 | wait(0.004); |
bbbobbbieo | 4:7584ff0426f1 | 42 | |
bbbobbbieo | 6:44d1079f076c | 43 | current_servo_position = current_servo_position+.005; |
bbbobbbieo | 6:44d1079f076c | 44 | if(current_servo_position >= 0.4) |
bbbobbbieo | 6:44d1079f076c | 45 | current_servo_position = 0.4; |
bbbobbbieo | 5:e7e4f1967fb8 | 46 | TFC_SetServo(0, current_servo_position); |
bbbobbbieo | 4:7584ff0426f1 | 47 | } |
bbbobbbieo | 4:7584ff0426f1 | 48 | |
bbbobbbieo | 4:7584ff0426f1 | 49 | else |
bbbobbbieo | 4:7584ff0426f1 | 50 | { |
bbbobbbieo | 4:7584ff0426f1 | 51 | TFC_BAT_LED1_ON; |
bbbobbbieo | 4:7584ff0426f1 | 52 | } |
bbbobbbieo | 4:7584ff0426f1 | 53 | |
bbbobbbieo | 6:44d1079f076c | 54 | if(rear_motor_enable_flag) |
bbbobbbieo | 6:44d1079f076c | 55 | { |
bbbobbbieo | 6:44d1079f076c | 56 | // |
bbbobbbieo | 6:44d1079f076c | 57 | //current_left_motor_speed = current_left_motor_speed + .3*(TFC_ReadPot(0)); |
bbbobbbieo | 6:44d1079f076c | 58 | //current_right_motor_speed = current_right_motor_speed + .3*(TFC_ReadPot(1)); |
bbbobbbieo | 6:44d1079f076c | 59 | |
bbbobbbieo | 6:44d1079f076c | 60 | current_left_motor_speed = .3*(TFC_ReadPot(0)); |
bbbobbbieo | 6:44d1079f076c | 61 | current_right_motor_speed = .3*(TFC_ReadPot(1)); |
bbbobbbieo | 6:44d1079f076c | 62 | |
bbbobbbieo | 6:44d1079f076c | 63 | if(current_left_motor_speed >= 0.4) |
bbbobbbieo | 6:44d1079f076c | 64 | current_left_motor_speed= 0.4; |
bbbobbbieo | 6:44d1079f076c | 65 | if(current_right_motor_speed >= 0.4) |
bbbobbbieo | 6:44d1079f076c | 66 | current_right_motor_speed= 0.4; |
bbbobbbieo | 6:44d1079f076c | 67 | if(current_left_motor_speed <= -0.4) |
bbbobbbieo | 6:44d1079f076c | 68 | current_left_motor_speed= -0.4; |
bbbobbbieo | 6:44d1079f076c | 69 | if(current_right_motor_speed <= -0.4) |
bbbobbbieo | 6:44d1079f076c | 70 | current_right_motor_speed= -0.4; |
bbbobbbieo | 6:44d1079f076c | 71 | |
bbbobbbieo | 6:44d1079f076c | 72 | TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed); |
bbbobbbieo | 6:44d1079f076c | 73 | } |
bbbobbbieo | 0:d57117b2188d | 74 | } |
bbbobbbieo | 0:d57117b2188d | 75 | } |
bbbobbbieo | 0:d57117b2188d | 76 | //hi guys |