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: mbed
Diff: main.cpp
- Revision:
- 1:aa0d93df1af1
- Parent:
- 0:7b9ca8e5811b
- Child:
- 2:90a9ed488f08
diff -r 7b9ca8e5811b -r aa0d93df1af1 main.cpp
--- a/main.cpp Thu Oct 29 09:43:31 2015 +0000
+++ b/main.cpp Thu Oct 29 10:47:24 2015 +0000
@@ -3,108 +3,48 @@
Serial pc(USBTX, USBRX);
-// Define pin for motor control
+// Define pins for motor control
+//horizontal motor
DigitalOut directionPin(D4);
PwmOut PWM(D5);
+//keypress motor
DigitalOut directionPin_key(D7);
PwmOut PWM_key(D6);
-DigitalIn buttonccw(PTA4);
-DigitalIn buttoncw(PTC6);
+//button to press the key
+DigitalIn button_key(PTC6);
+//pot meters to act as emg filter substitutes
AnalogIn left_pot(A0);
AnalogIn right_pot(A1);
+
+//variables to hold the values of the pot meters
double emg_left;
double emg_right;
+//int to check if the button is pressed
const int Button_move_pressed = 0;
-const int Button_back_pressed = 0;
+//values for clockwise and counter clockwise movement
const int cw = 1;
const int ccw = 0;
-//right button
-DigitalIn button_left(PTC4);
-DigitalIn button_right(PTC6);
+
int main()
{
- pc.printf("at the begin");
- //directionPin_key.write(cw);
- //PWM_key.write(0);
-
- //aansturen.attach( &Go_flag_motor, 0.01f ); // 100 Hz // timer 0.00001f motor keeps spinning
- //HIDScope_timer.attach(&Go_flag_HIDScope, 0.02);//0.02 had worked
- //Filteren_timer.attach(&Go_flag_filteren,0.04);// 0.04 had worked
while(1) {
-
- /*
- if(Flag_filteren) {
- Flag_filteren = false;
- // filter left and set bool
- filter_signal_hid_left = Filteren_left(analog_emg_left.read());
-
- if (filter_signal_hid_left > high_threshold) {
- left_movement = true;
- } else if (filter_signal_hid_left < low_threshold) {
- left_movement = false;
- }
- // make filter right and set bool
- filter_signal_hid_right = Filteren_right(analog_emg_right.read());
-
- if (filter_signal_hid_right > high_threshold) {
- right_movement = true;
- } else if (filter_signal_hid_right < low_threshold) {
- right_movement = false;
- }
-
-
- }
-
-
-
- if(Flag_HIDScope) {
- Flag_HIDScope = false;
- HIDScope_kijken();
-
- }
-
-
- if(flag_motor) {
- flag_motor = false;
- motor1_Controller();
-
- }
-
- if( left_movement and right_movement == false) {
- setpoint = making_setpoint(cw);
-
-
- }
- else if(right_movement and left_movement == false ) {
- setpoint = making_setpoint(ccw);
- }
-
- else if(right_movement and left_movement) {
-
- PWM_key.write(1);
- //pc.printf("I am working");
- }
- else {
- PWM_key.write(0);
- // pc.printf("resting /n");
- }
- */
-
+ //read the 'emg' values
emg_left = left_pot.read();
emg_right = right_pot.read();
+ //if left above threashold and right below; move left
while (emg_left > 0.5 and emg_right < 0.5)
{
directionPin.write(cw);
PWM.write(1);
- pc.printf("left \n");
+ //new left value to check (in while loop condition) if it has fallen below threashold
emg_left = left_pot.read();
}
@@ -112,32 +52,28 @@
{
directionPin.write(ccw);
PWM.write(1);
- pc.printf("right \n");
+ //new right value, to check in while loop condition
emg_right = right_pot.read();
}
- if (button_right.read() == Button_move_pressed)
+ if (button_key.read() == Button_move_pressed)
{
- pc.printf("button move \n");
//move to key
directionPin_key.write(cw);
- PWM_key.write(0.3);
- wait(0.8);
- PWM.write(0);
- wait(0.3);
+ PWM_key.write(1);
+ wait(0.14); //time it takes pwm of one to reach the key
+ //pause at the key for one second
+ PWM_key.write(0);
+ wait(1);
+ //move bakc to the starting position
directionPin_key.write(ccw);
- PWM_key.write(0.3);
- wait(0.8);
+ PWM_key.write(1);
+ //time needs to be slightly longer than moving forward (no answer why)
+ wait(0.165f);
}
- /*
- while (button_left.read() == Button_back_pressed)
- {
- //move back to start
- pc.printf("button move backwards \n");
- directionPin_key.write(ccw);
- PWM_key.write(0.3);
- }
- */
+
+ /// set spped values of both motors to zero so if no muscles are contracted, no motors move
+ //more of a safety catch than actually necessary
PWM_key.write(0);
PWM.write(0);
}