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:
- 5:74fcd196ff96
- Parent:
- 4:41bbbaecd322
- Child:
- 6:8d2171811f14
--- a/main.cpp Fri Nov 11 01:54:18 2016 +0000 +++ b/main.cpp Fri Nov 11 02:31:30 2016 +0000 @@ -1,181 +1,16 @@ -#include "mbed.h" - -AnalogIn ain(A0); -Serial pc(USBTX, USBRX); -DigitalOut dout(LED1); +#include "QEI.h" - //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); - } +Serial pc(USBTX, USBRX); +//Use X4 encoding. +//QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING); +//Use X2 encoding by default. +QEI wheel (p29, p30, NC, 624); - - // 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); - } +int main() { - - // 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; - } + while(1){ wait(0.1); - pc.printf("The value is %f\r\n", ain.read()); + pc.printf("Pulses is: %i\n", wheel.getPulses()); } -} \ No newline at end of file + +} \ No newline at end of file