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
- Committer:
- dlweakley
- Date:
- 2016-11-11
- Revision:
- 4:41bbbaecd322
- Parent:
- 1:b0fc2c9a5d06
- Child:
- 5:74fcd196ff96
File content as of revision 4:41bbbaecd322:
#include "mbed.h" AnalogIn ain(A0); Serial pc(USBTX, USBRX); DigitalOut dout(LED1); //motor pins DigitalOut d2(PTB23); DigitalOut M1PWM(PTC4); DigitalOut M2PWM(PTD0); DigitalOut M1DIR(PTC3); DigitalOut M2DIR(PTC12); void anticlockwise(int steps){ for (int i = 0; i < 8; i++) { switch (i) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps case 0: { M1PWM=1; M1DIR=0; M2PWM=0; M2DIR=0; //wait_ms(1); } break; case 1: { M1PWM=1; M1DIR=0; M2PWM=1; M2DIR=0; //wait_ms(1); } break; case 2: { M1PWM=0; M1DIR=0; M2PWM=1; M2DIR=0; //wait_ms(1); } break; case 3: { M1PWM=1; M1DIR=1; M2PWM=1; M2DIR=0; //wait_ms(1); } break; case 4: { M1PWM=1; M1DIR=1; M2PWM=0; M2DIR=0; //wait_ms(1); } break; case 5: { M1PWM=1; M1DIR=1; M2PWM=1; M2DIR=1; //wait_ms(1); } break; case 6: { M1PWM=0; M1DIR=0; M2PWM=1; M2DIR=1; //wait_ms(1); } break; case 7: { M1PWM=1; M1DIR=0; M2PWM=1; M2DIR=1; //wait_ms(1); } break; } wait_us(500); } // wait time defines the speed } void clockwise(){ for (int i = 0; i < 8; i++) { switch (i) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps case 0: { M1PWM=1; M1DIR=0; M2PWM=1; M2DIR=1; //wait_us(20); } break; case 1: { M1PWM=0; M1DIR=0; M2PWM=1; M2DIR=1; //wait_us(20); } break; case 2: { M1PWM=1; M1DIR=1; M2PWM=1; M2DIR=1; //wait_us(20); } break; case 3: { M1PWM=1; M1DIR=1; M2PWM=0; M2DIR=0; //wait_us(20); } break; case 4: { M1PWM=1; M1DIR=1; M2PWM=1; M2DIR=0; //wait_us(20); } break; case 5: { M1PWM=0; M1DIR=0; M2PWM=1; M2DIR=0; //wait_us(20); } break; case 6: { M1PWM=1; M1DIR=0; M2PWM=1; M2DIR=0; //wait_us(20); } break; case 7: { M1PWM=1; M1DIR=0; M2PWM=0; M2DIR=0; //wait_us(20); } break; } wait_us(500); } // wait time defines the speed } int main() { pc.baud(9600); pc.printf("Getting values\r\n"); while(1) { if(ain > 0.3f) { dout = 1; } else { dout = 0; } wait(0.1); pc.printf("The value is %f\r\n", ain.read()); } }