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.
Diff: main.cpp
- Revision:
- 4:41bbbaecd322
- Parent:
- 1:b0fc2c9a5d06
- Child:
- 5:74fcd196ff96
--- a/main.cpp Fri Nov 11 01:11:46 2016 +0000 +++ b/main.cpp Fri Nov 11 01:54:18 2016 +0000 @@ -3,6 +3,167 @@ 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);