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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * 00002 * This times a race with up to two separate timers * 00003 * which start whenever a button press interrupt is * 00004 * detected. The timers are stopped only by * 00005 * recording a tripwire interrupt which will save * 00006 * the time and output it to the serial port. * 00007 * * 00008 * Created by: Michael Dushkoff (mad1841@rit.edu) * 00009 * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00010 00011 #include "mbed.h" 00012 #include "mMotor.h" 00013 00014 /* Stepper motor constants, (change based on motor) */ 00015 int step_speed = 5000; // set default motor speed 4000 (fast) 5000 (natural) 00016 int numstep1 = 30; // Defines rising turn (200) 00017 int numstep2 = 30; // Defines falling turn (20) 00018 00019 DigitalOut txo(p30); //Defines the transmit pin output 00020 00021 /* Create two stepper motor controllers */ 00022 mMotor mt1(p33, p34, p35, p36); 00023 mMotor mt2(p11, p12, p13, p14); 00024 00025 /* Create two individual timers */ 00026 Timer t1; 00027 Timer t2; 00028 00029 /* Interrupt sensors */ 00030 InterruptIn bInt1(p23); 00031 InterruptIn bInt2(p24); 00032 00033 /* Indicator LEDs */ 00034 DigitalOut iled1(LED1); 00035 DigitalOut iled2(LED4); 00036 DigitalOut tled1(LED2); //Timer LED1 00037 DigitalOut tled2(LED3); //Timer LED2 00038 00039 /* Tells when to stop the timer */ 00040 int end1 = 0; 00041 int end2 = 0; 00042 00043 /* This is a print button that allows the time to be outputted */ 00044 DigitalIn button(p8); 00045 00046 /* Rise detection */ 00047 int rise = 0; 00048 00049 /* Setup detection */ 00050 int setup = 1; 00051 00052 void transmit(){ 00053 txo = 0; 00054 wait(0.01); 00055 txo = 1; 00056 wait(0.01); 00057 txo = 0; 00058 wait(0.01); 00059 txo = 1; 00060 } 00061 00062 /* This detects button interrupt 1 */ 00063 void b1(){ 00064 if (setup == 0){ 00065 mt1.step(numstep2,0,step_speed); 00066 transmit(); 00067 setup = 1; 00068 } 00069 } 00070 00071 /* This detects button interrupt 2 */ 00072 void b2(){ 00073 if (setup == 1){ 00074 mt1.step(numstep1,1,step_speed); 00075 setup = 0; 00076 } 00077 } 00078 00079 int main() { 00080 /* Drive transmit pin */ 00081 txo = 1; 00082 00083 /* Put into setup mode */ 00084 setup = 1; 00085 00086 /* Turn LEDs on */ 00087 iled1 = 1; 00088 iled2 = 1; 00089 tled1 = 1; 00090 tled2 = 1; 00091 00092 printf("Starting up...\n\r"); 00093 00094 /* Attach interrupt service routine to pins */ 00095 bInt1.rise(&b1); 00096 bInt2.rise(&b2); 00097 00098 /* Set the LEDs off */ 00099 iled1 = 0; 00100 iled2 = 0; 00101 tled1 = 0; 00102 tled2 = 0; 00103 00104 setup = 1; 00105 00106 printf("Ready!\n\r"); 00107 while(1) { 00108 // Do nothing 00109 } 00110 }
Generated on Tue Jul 19 2022 05:12:15 by
1.7.2