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.
Dependencies: QEI mbed HIDScope
Diff: main.cpp
- Revision:
- 2:cb7d7e31e30e
- Parent:
- 1:ccb2f96c393a
- Child:
- 3:e533800b2ef8
diff -r ccb2f96c393a -r cb7d7e31e30e main.cpp
--- a/main.cpp Fri Oct 12 08:31:16 2018 +0000
+++ b/main.cpp Sun Oct 14 10:59:42 2018 +0000
@@ -4,45 +4,31 @@
#define SERIAL_BAUD 115200
Serial pc(USBTX,USBRX);
-int counts;
-//Kenneth was here
DigitalOut dirpin(D4);
+DigitalOut dirpin_2(D6);
+
PwmOut pwmpin(D5);
-AnalogIn pot_1(A1);
-DigitalOut dirpin_2(D6);
PwmOut pwmpin_2(D7);
-AnalogIn pot_2(A2);
+
+AnalogIn pot_1(A1); //only using one potmeter for both motors, eventually just use a signal created by program or EMG-signals
- QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING);
+
+QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); //channel A=D12, channel B=D13
int main()
{
+ //float out_1=1.0f; //set potmeter signal as a predetermined digital signal
+ pc.baud(115200); //also set baudrate to 115200 in teraterm!
pc.printf("start\r\n");
- pc.baud(115200);
-
- pwmpin.period_us(60);
- counts = Encoder.getPulses();
-
- while(true){
- //motor 1
- float out_1 = pot_1 * 2.0f;
- float out_2 = out_1 - 1.0f;
-
- dirpin.write(out_2 < 0);
+
+ pwmpin.period_us(60); //???
- pwmpin = fabs (out_2);
-
- // motor 2
- float out_3 = pot_2 * 2.0f;
- float out_4 = out_3 - 1.0f;
-
- dirpin_2.write(out_4 < 0);
-
- pwmpin_2 = fabs (out_4);
-
- pc.printf("%i\r\n", counts);
-
- wait(0.01);
+ while(1){
+ float out_1 = (pot_1 * 2.0f) - 1.0f; //scales potmeter signal from 0 to 1 into -1 to 1
+ dirpin.write(out_1 < 0); //sets direction of motor? if negative =true (1), if positive =false (0)
+ pwmpin = fabs (out_1); //sets speed of motor?
+ pc.printf("%i\r\n", Encoder.getPulses()); //prints the amount of counts
+ wait(0.1); //repeat loop every 0.01 sec
}
}
\ No newline at end of file