
Coiling jig experiment with buttons for coiling, annealing and testing.
Dependencies: TextLCD
main.cpp@0:7795c79c9480, 2018-12-21 (annotated)
- Committer:
- yphilippou
- Date:
- Fri Dec 21 15:46:23 2018 +0000
- Revision:
- 0:7795c79c9480
Buttons added.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yphilippou | 0:7795c79c9480 | 1 | #include "mbed.h" |
yphilippou | 0:7795c79c9480 | 2 | #include "TextLCD.h" |
yphilippou | 0:7795c79c9480 | 3 | #include "SETUP.hpp" |
yphilippou | 0:7795c79c9480 | 4 | |
yphilippou | 0:7795c79c9480 | 5 | //#include <iostream> |
yphilippou | 0:7795c79c9480 | 6 | //using namespace std; |
yphilippou | 0:7795c79c9480 | 7 | //Serial pc(USBTX, USBRX); //Define serial namespace so the serial comms can be printed to |
yphilippou | 0:7795c79c9480 | 8 | //TextLCD lcd(D0,D1,D4,D5,D6,D7); // rs, e, d4-d7 |
yphilippou | 0:7795c79c9480 | 9 | |
yphilippou | 0:7795c79c9480 | 10 | int counter; |
yphilippou | 0:7795c79c9480 | 11 | DigitalOut myled(LED1); |
yphilippou | 0:7795c79c9480 | 12 | DigitalIn B1(PE_15); |
yphilippou | 0:7795c79c9480 | 13 | DigitalIn B2(PE_14); |
yphilippou | 0:7795c79c9480 | 14 | DigitalIn B3(PE_12); |
yphilippou | 0:7795c79c9480 | 15 | DigitalIn B4(PE_10); |
yphilippou | 0:7795c79c9480 | 16 | |
yphilippou | 0:7795c79c9480 | 17 | PwmOut M1(PE_8); |
yphilippou | 0:7795c79c9480 | 18 | |
yphilippou | 0:7795c79c9480 | 19 | //functions |
yphilippou | 0:7795c79c9480 | 20 | void StartUp(){ |
yphilippou | 0:7795c79c9480 | 21 | M1.period(0.01); // set PWM period to 10 ms |
yphilippou | 0:7795c79c9480 | 22 | M1=1; // set duty cycle to 100% |
yphilippou | 0:7795c79c9480 | 23 | wait(6); |
yphilippou | 0:7795c79c9480 | 24 | M1=0; |
yphilippou | 0:7795c79c9480 | 25 | return; |
yphilippou | 0:7795c79c9480 | 26 | } |
yphilippou | 0:7795c79c9480 | 27 | void Ending(){ |
yphilippou | 0:7795c79c9480 | 28 | M1.period(0.01); // set PWM period to 10 ms |
yphilippou | 0:7795c79c9480 | 29 | M1=0.5; // set duty cycle to 50% |
yphilippou | 0:7795c79c9480 | 30 | wait(3); |
yphilippou | 0:7795c79c9480 | 31 | M1=0; |
yphilippou | 0:7795c79c9480 | 32 | return; |
yphilippou | 0:7795c79c9480 | 33 | } |
yphilippou | 0:7795c79c9480 | 34 | void Constant(){ |
yphilippou | 0:7795c79c9480 | 35 | M1=1; // set duty cycle to 100% |
yphilippou | 0:7795c79c9480 | 36 | wait(6); |
yphilippou | 0:7795c79c9480 | 37 | M1=0.75; //75% |
yphilippou | 0:7795c79c9480 | 38 | wait(3); |
yphilippou | 0:7795c79c9480 | 39 | M1=0; |
yphilippou | 0:7795c79c9480 | 40 | wait(6); |
yphilippou | 0:7795c79c9480 | 41 | } |
yphilippou | 0:7795c79c9480 | 42 | void LongTest(){ |
yphilippou | 0:7795c79c9480 | 43 | M1=1; // set duty cycle to 100% |
yphilippou | 0:7795c79c9480 | 44 | wait(9); |
yphilippou | 0:7795c79c9480 | 45 | M1 = 0; |
yphilippou | 0:7795c79c9480 | 46 | wait(6); |
yphilippou | 0:7795c79c9480 | 47 | } |
yphilippou | 0:7795c79c9480 | 48 | |
yphilippou | 0:7795c79c9480 | 49 | void Holding(){ |
yphilippou | 0:7795c79c9480 | 50 | M1.period(0.01); // set PWM period to 10 ms |
yphilippou | 0:7795c79c9480 | 51 | M1=0.2; // set duty cycle to 20% |
yphilippou | 0:7795c79c9480 | 52 | wait(3); |
yphilippou | 0:7795c79c9480 | 53 | M1=0; |
yphilippou | 0:7795c79c9480 | 54 | return; |
yphilippou | 0:7795c79c9480 | 55 | } |
yphilippou | 0:7795c79c9480 | 56 | void Cooling(){ |
yphilippou | 0:7795c79c9480 | 57 | M1.period(0.01); |
yphilippou | 0:7795c79c9480 | 58 | M1=0; // set duty cycle to 0% |
yphilippou | 0:7795c79c9480 | 59 | wait(5); |
yphilippou | 0:7795c79c9480 | 60 | return; |
yphilippou | 0:7795c79c9480 | 61 | } |
yphilippou | 0:7795c79c9480 | 62 | void Training(){ |
yphilippou | 0:7795c79c9480 | 63 | counter = 0; |
yphilippou | 0:7795c79c9480 | 64 | for ( ; counter < 6; counter++) { // |
yphilippou | 0:7795c79c9480 | 65 | M1.period(0.01); // set PWM period to 10 ms |
yphilippou | 0:7795c79c9480 | 66 | M1=1; // set duty cycle to 100% |
yphilippou | 0:7795c79c9480 | 67 | wait(2); |
yphilippou | 0:7795c79c9480 | 68 | M1=0; |
yphilippou | 0:7795c79c9480 | 69 | wait(6); |
yphilippou | 0:7795c79c9480 | 70 | } |
yphilippou | 0:7795c79c9480 | 71 | M1=1; // set duty cycle to 100% |
yphilippou | 0:7795c79c9480 | 72 | wait(6); |
yphilippou | 0:7795c79c9480 | 73 | M1=0.5; // set duty cycle to 50% |
yphilippou | 0:7795c79c9480 | 74 | wait(3); |
yphilippou | 0:7795c79c9480 | 75 | M1=0; // set duty cycle to 0% |
yphilippou | 0:7795c79c9480 | 76 | wait(5); |
yphilippou | 0:7795c79c9480 | 77 | return; |
yphilippou | 0:7795c79c9480 | 78 | } |
yphilippou | 0:7795c79c9480 | 79 | |
yphilippou | 0:7795c79c9480 | 80 | int main() { |
yphilippou | 0:7795c79c9480 | 81 | |
yphilippou | 0:7795c79c9480 | 82 | // pc.baud(9600); |
yphilippou | 0:7795c79c9480 | 83 | printf("Putty test\n"); //Request command in the terminal |
yphilippou | 0:7795c79c9480 | 84 | // lcd.printf("Hello World!\n"); |
yphilippou | 0:7795c79c9480 | 85 | printf("Please input a number of rotations\n"); |
yphilippou | 0:7795c79c9480 | 86 | |
yphilippou | 0:7795c79c9480 | 87 | while(1) { |
yphilippou | 0:7795c79c9480 | 88 | myled = 1; // LED is ON |
yphilippou | 0:7795c79c9480 | 89 | wait(1); |
yphilippou | 0:7795c79c9480 | 90 | if(B1) |
yphilippou | 0:7795c79c9480 | 91 | { |
yphilippou | 0:7795c79c9480 | 92 | myled = 0; // LED is OFF |
yphilippou | 0:7795c79c9480 | 93 | printf("60 Turns\n"); |
yphilippou | 0:7795c79c9480 | 94 | STEPPER_MOTOR_1.Rotate_Steps(60); |
yphilippou | 0:7795c79c9480 | 95 | myled = 1; // LED is ON |
yphilippou | 0:7795c79c9480 | 96 | wait(1); // |
yphilippou | 0:7795c79c9480 | 97 | myled = 0; // LED is OFF |
yphilippou | 0:7795c79c9480 | 98 | wait(1); // 1 sec |
yphilippou | 0:7795c79c9480 | 99 | printf("Coiling Complete\n"); |
yphilippou | 0:7795c79c9480 | 100 | } |
yphilippou | 0:7795c79c9480 | 101 | else if(B2) |
yphilippou | 0:7795c79c9480 | 102 | { |
yphilippou | 0:7795c79c9480 | 103 | myled = 0; // LED is OFF |
yphilippou | 0:7795c79c9480 | 104 | printf("Training\n"); |
yphilippou | 0:7795c79c9480 | 105 | Training(); |
yphilippou | 0:7795c79c9480 | 106 | myled = 1; // LED is ON |
yphilippou | 0:7795c79c9480 | 107 | wait(1); // |
yphilippou | 0:7795c79c9480 | 108 | myled = 0; // LED is OFF |
yphilippou | 0:7795c79c9480 | 109 | wait(1); // 1 sec |
yphilippou | 0:7795c79c9480 | 110 | printf("Training Complete\n"); |
yphilippou | 0:7795c79c9480 | 111 | } |
yphilippou | 0:7795c79c9480 | 112 | else if(B3) |
yphilippou | 0:7795c79c9480 | 113 | { |
yphilippou | 0:7795c79c9480 | 114 | myled = 0; // LED is OFF |
yphilippou | 0:7795c79c9480 | 115 | printf("Constant\n"); |
yphilippou | 0:7795c79c9480 | 116 | Constant(); |
yphilippou | 0:7795c79c9480 | 117 | printf("Constant Complete\n"); |
yphilippou | 0:7795c79c9480 | 118 | } |
yphilippou | 0:7795c79c9480 | 119 | else if(B4) |
yphilippou | 0:7795c79c9480 | 120 | { |
yphilippou | 0:7795c79c9480 | 121 | myled = 0; // LED is OFF |
yphilippou | 0:7795c79c9480 | 122 | printf("LongTest\n"); |
yphilippou | 0:7795c79c9480 | 123 | LongTest(); |
yphilippou | 0:7795c79c9480 | 124 | printf("LongTest Complete\n"); |
yphilippou | 0:7795c79c9480 | 125 | } |
yphilippou | 0:7795c79c9480 | 126 | else { |
yphilippou | 0:7795c79c9480 | 127 | myled = 1; // LED is ON |
yphilippou | 0:7795c79c9480 | 128 | } |
yphilippou | 0:7795c79c9480 | 129 | } |
yphilippou | 0:7795c79c9480 | 130 | |
yphilippou | 0:7795c79c9480 | 131 | } |
yphilippou | 0:7795c79c9480 | 132 |