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
00001 #include "mbed.h" 00002 00003 //motor spec 00004 #define STEP_SIZE 1.8 00005 #define MAX_SPEED 50 00006 00007 //algo 00008 #define SPEED_STEP 5 00009 00010 DigitalOut motor_a1(p30); 00011 DigitalOut motor_a2(p29); 00012 DigitalOut motor_b1(p28); 00013 DigitalOut motor_b2(p27); 00014 InterruptIn bp_up(p22); 00015 InterruptIn bp_dw(p21); 00016 00017 float speed = SPEED_STEP; 00018 00019 void SpeedUp() { 00020 if (speed < MAX_SPEED) 00021 speed += SPEED_STEP; 00022 } 00023 00024 void SpeedDw() { 00025 if (speed > (-1 * MAX_SPEED)) 00026 speed -= SPEED_STEP; 00027 } 00028 00029 int main() { 00030 unsigned char pos = 0; 00031 unsigned char cycle[8][4] = { 00032 {1, 0, 0, 0}, 00033 {1, 0, 1, 0}, 00034 {0, 0, 1, 0}, 00035 {0, 1, 1, 0}, 00036 {0, 1, 0, 0}, 00037 {0, 1, 0, 1}, 00038 {0, 0, 0, 1}, 00039 {1, 0, 0, 1} 00040 }; 00041 00042 bp_up.rise(&SpeedUp); 00043 bp_dw.rise(&SpeedDw); 00044 00045 while (1) { 00046 motor_a1 = cycle[pos][0]; 00047 motor_a2 = cycle[pos][1]; 00048 motor_b1 = cycle[pos][2]; 00049 motor_b2 = cycle[pos][3]; 00050 00051 if (speed != 0) { 00052 if (speed > 0) { 00053 if (pos == 7) 00054 pos = 0; 00055 else 00056 pos++; 00057 } 00058 else { 00059 if (pos == 0) 00060 pos = 7; 00061 else 00062 pos--; 00063 } 00064 00065 wait((60.0 * STEP_SIZE) / (360.0 * 8.0 * abs(speed))); 00066 } else { 00067 00068 } 00069 } 00070 00071 return 1; 00072 }
Generated on Mon Aug 1 2022 16:36:40 by
1.7.2