![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
RAM error
Dependencies: F746_GUI mbed StepperMotorX2Y
main.cpp@0:fda2fbc0d37b, 2020-11-11 (annotated)
- Committer:
- Abdel64
- Date:
- Wed Nov 11 11:10:46 2020 +0000
- Revision:
- 0:fda2fbc0d37b
- Child:
- 1:39faa12c5a52
Classe fille steppers OK
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Abdel64 | 0:fda2fbc0d37b | 1 | //----------------------------------------------------------------------- |
Abdel64 | 0:fda2fbc0d37b | 2 | // GuiBase とその派生クラスのデモプログラム |
Abdel64 | 0:fda2fbc0d37b | 3 | // Demo program for GuiBase class and its derivertive classes |
Abdel64 | 0:fda2fbc0d37b | 4 | // |
Abdel64 | 0:fda2fbc0d37b | 5 | // GuiBase, Button, ButtonGroup, Label, NumericLabel, BlinkLabel, |
Abdel64 | 0:fda2fbc0d37b | 6 | // SeekBar, SeekbarGroup, NumericUpDown |
Abdel64 | 0:fda2fbc0d37b | 7 | // |
Abdel64 | 0:fda2fbc0d37b | 8 | // <インポートしたライブラリのリビジョン> |
Abdel64 | 0:fda2fbc0d37b | 9 | // F746_GUI 33 |
Abdel64 | 0:fda2fbc0d37b | 10 | // mbed 161 |
Abdel64 | 0:fda2fbc0d37b | 11 | // |
Abdel64 | 0:fda2fbc0d37b | 12 | // 2018/03/12, Copyright (c) 2018 MIKAMI, Naoki |
Abdel64 | 0:fda2fbc0d37b | 13 | //----------------------------------------------------------------------- |
Abdel64 | 0:fda2fbc0d37b | 14 | |
Abdel64 | 0:fda2fbc0d37b | 15 | #include "F746_GUI.hpp" |
Abdel64 | 0:fda2fbc0d37b | 16 | #include "Stepper.h" |
Abdel64 | 0:fda2fbc0d37b | 17 | |
Abdel64 | 0:fda2fbc0d37b | 18 | DigitalIn FourcheLibre(PA_8); |
Abdel64 | 0:fda2fbc0d37b | 19 | int speed_start = 10; |
Abdel64 | 0:fda2fbc0d37b | 20 | int speed_max = 1000; |
Abdel64 | 0:fda2fbc0d37b | 21 | |
Abdel64 | 0:fda2fbc0d37b | 22 | int main() |
Abdel64 | 0:fda2fbc0d37b | 23 | { |
Abdel64 | 0:fda2fbc0d37b | 24 | // ******** INIT GUI ********* |
Abdel64 | 0:fda2fbc0d37b | 25 | NumericLabel<int> bStart(380, 240, "Wait for Start", Label::LEFT, Font12, LCD_COLOR_MAGENTA); |
Abdel64 | 0:fda2fbc0d37b | 26 | |
Abdel64 | 0:fda2fbc0d37b | 27 | Button Start(250, 220, 120, 40, "START", Font12, |
Abdel64 | 0:fda2fbc0d37b | 28 | GuiBase::ENUM_TEXT, GuiBase::ENUM_BACK, |
Abdel64 | 0:fda2fbc0d37b | 29 | LCD_COLOR_DARKGREEN, LCD_COLOR_GREEN); |
Abdel64 | 0:fda2fbc0d37b | 30 | |
Abdel64 | 0:fda2fbc0d37b | 31 | Label stepY(130, 20, "STEPPERs Y", Label::CENTER, Font16); |
Abdel64 | 0:fda2fbc0d37b | 32 | ButtonGroup bDir_Y(50, 70, 80, 50, 3, (string[]){"^","v","Pause"}, 0, 0, 2); |
Abdel64 | 0:fda2fbc0d37b | 33 | bDir_Y.TouchedColor(2); |
Abdel64 | 0:fda2fbc0d37b | 34 | NumericLabel<int> bDir_Y_label(130, 35, "", Label::CENTER , Font12); |
Abdel64 | 0:fda2fbc0d37b | 35 | bDir_Y_label.Draw("Pause",1); |
Abdel64 | 0:fda2fbc0d37b | 36 | NumericLabel<int> bCount_Y_label(130, 50, "", Label::CENTER , Font12); |
Abdel64 | 0:fda2fbc0d37b | 37 | bCount_Y_label.Draw("Not started",1); |
Abdel64 | 0:fda2fbc0d37b | 38 | |
Abdel64 | 0:fda2fbc0d37b | 39 | Label stepX(320, 20, "STEPPER X", Label::CENTER, Font16); |
Abdel64 | 0:fda2fbc0d37b | 40 | ButtonGroup bDir_X(260, 70, 80, 50, 3, (string[]){"<<",">>","Pause"}, 0, 0, 2); |
Abdel64 | 0:fda2fbc0d37b | 41 | bDir_X.TouchedColor(2); |
Abdel64 | 0:fda2fbc0d37b | 42 | NumericLabel<int> bDir_X_label(320, 35, "", Label::CENTER , Font12); |
Abdel64 | 0:fda2fbc0d37b | 43 | bDir_X_label.Draw("Pause",1); |
Abdel64 | 0:fda2fbc0d37b | 44 | NumericLabel<int> bCount_X_label(320, 50, "", Label::CENTER , Font12); |
Abdel64 | 0:fda2fbc0d37b | 45 | bCount_X_label.Draw("Not started",1); |
Abdel64 | 0:fda2fbc0d37b | 46 | |
Abdel64 | 0:fda2fbc0d37b | 47 | SeekBar barSpeed(20, 250, 200, 0, speed_max, speed_start, "0", "", "1000"); |
Abdel64 | 0:fda2fbc0d37b | 48 | NumericLabel<int> barSpeed_legend(110, 205, "Speed : 10", Label::CENTER , Font12); |
Abdel64 | 0:fda2fbc0d37b | 49 | barSpeed_legend.Draw("Speed : %d",barSpeed.GetIntValue()); |
Abdel64 | 0:fda2fbc0d37b | 50 | |
Abdel64 | 0:fda2fbc0d37b | 51 | // ******** INIT STEPPER ****** |
Abdel64 | 0:fda2fbc0d37b | 52 | // stepper(PinName _en, PinName _stepPin, PinName dirG, PinName dirD) |
Abdel64 | 0:fda2fbc0d37b | 53 | steppers Steppers_Y (PB_8,PB_9,PB_14,PB_15); |
Abdel64 | 0:fda2fbc0d37b | 54 | Steppers_Y.disable(); |
Abdel64 | 0:fda2fbc0d37b | 55 | stepper Stepper_X (PB_4,PC_6,PC_7); |
Abdel64 | 0:fda2fbc0d37b | 56 | Stepper_X.disable(); |
Abdel64 | 0:fda2fbc0d37b | 57 | int Y_en, Y_dir, X_en, X_dir, Y_speed, X_speed, Y_count, X_count ; |
Abdel64 | 0:fda2fbc0d37b | 58 | Y_speed = X_speed = speed_start; |
Abdel64 | 0:fda2fbc0d37b | 59 | Y_en = X_en = 0; |
Abdel64 | 0:fda2fbc0d37b | 60 | Y_count = X_count = 0; |
Abdel64 | 0:fda2fbc0d37b | 61 | |
Abdel64 | 0:fda2fbc0d37b | 62 | int first = 1; |
Abdel64 | 0:fda2fbc0d37b | 63 | int num; |
Abdel64 | 0:fda2fbc0d37b | 64 | |
Abdel64 | 0:fda2fbc0d37b | 65 | // ***** WAIT FOR START ***** |
Abdel64 | 0:fda2fbc0d37b | 66 | while(!Start.Touched()){ |
Abdel64 | 0:fda2fbc0d37b | 67 | if (first){ |
Abdel64 | 0:fda2fbc0d37b | 68 | bStart.Draw("Wait for Start",0); |
Abdel64 | 0:fda2fbc0d37b | 69 | first = 0; |
Abdel64 | 0:fda2fbc0d37b | 70 | } |
Abdel64 | 0:fda2fbc0d37b | 71 | } |
Abdel64 | 0:fda2fbc0d37b | 72 | |
Abdel64 | 0:fda2fbc0d37b | 73 | // ******* RUN ***** |
Abdel64 | 0:fda2fbc0d37b | 74 | // ***************** |
Abdel64 | 0:fda2fbc0d37b | 75 | first = 1; |
Abdel64 | 0:fda2fbc0d37b | 76 | |
Abdel64 | 0:fda2fbc0d37b | 77 | while (true) |
Abdel64 | 0:fda2fbc0d37b | 78 | { |
Abdel64 | 0:fda2fbc0d37b | 79 | |
Abdel64 | 0:fda2fbc0d37b | 80 | if (first){ |
Abdel64 | 0:fda2fbc0d37b | 81 | bStart.Draw("Started",1); |
Abdel64 | 0:fda2fbc0d37b | 82 | first = 0; |
Abdel64 | 0:fda2fbc0d37b | 83 | } |
Abdel64 | 0:fda2fbc0d37b | 84 | |
Abdel64 | 0:fda2fbc0d37b | 85 | if (barSpeed.Slide()){ |
Abdel64 | 0:fda2fbc0d37b | 86 | Y_speed = barSpeed.GetIntValue(); |
Abdel64 | 0:fda2fbc0d37b | 87 | X_speed = Y_speed; |
Abdel64 | 0:fda2fbc0d37b | 88 | barSpeed_legend.Draw("Speed : %d",barSpeed.GetIntValue()); |
Abdel64 | 0:fda2fbc0d37b | 89 | } |
Abdel64 | 0:fda2fbc0d37b | 90 | |
Abdel64 | 0:fda2fbc0d37b | 91 | if (bDir_Y.GetTouchedNumber(num)){ |
Abdel64 | 0:fda2fbc0d37b | 92 | switch (num) |
Abdel64 | 0:fda2fbc0d37b | 93 | { |
Abdel64 | 0:fda2fbc0d37b | 94 | case 0: Y_en = 1; |
Abdel64 | 0:fda2fbc0d37b | 95 | Y_dir = 1; |
Abdel64 | 0:fda2fbc0d37b | 96 | bDir_Y_label.Draw("Avant (dir:%d)",Y_dir); |
Abdel64 | 0:fda2fbc0d37b | 97 | break; |
Abdel64 | 0:fda2fbc0d37b | 98 | case 1: Y_en = 1; |
Abdel64 | 0:fda2fbc0d37b | 99 | Y_dir = 0; |
Abdel64 | 0:fda2fbc0d37b | 100 | bDir_Y_label.Draw("Arriere (dir:%d)",Y_dir); |
Abdel64 | 0:fda2fbc0d37b | 101 | break; |
Abdel64 | 0:fda2fbc0d37b | 102 | case 2: Y_en = 0; |
Abdel64 | 0:fda2fbc0d37b | 103 | bDir_Y_label.Draw("Pause",0); |
Abdel64 | 0:fda2fbc0d37b | 104 | |
Abdel64 | 0:fda2fbc0d37b | 105 | break; |
Abdel64 | 0:fda2fbc0d37b | 106 | } |
Abdel64 | 0:fda2fbc0d37b | 107 | } |
Abdel64 | 0:fda2fbc0d37b | 108 | |
Abdel64 | 0:fda2fbc0d37b | 109 | if (bDir_X.GetTouchedNumber(num)){ |
Abdel64 | 0:fda2fbc0d37b | 110 | switch (num) |
Abdel64 | 0:fda2fbc0d37b | 111 | { |
Abdel64 | 0:fda2fbc0d37b | 112 | case 0: X_en = 1; |
Abdel64 | 0:fda2fbc0d37b | 113 | X_dir = 1; |
Abdel64 | 0:fda2fbc0d37b | 114 | bDir_X_label.Draw("Gauche (dir:%d)",X_dir); |
Abdel64 | 0:fda2fbc0d37b | 115 | break; |
Abdel64 | 0:fda2fbc0d37b | 116 | case 1: X_en = 1; |
Abdel64 | 0:fda2fbc0d37b | 117 | X_dir = 0; |
Abdel64 | 0:fda2fbc0d37b | 118 | bDir_X_label.Draw("Droite (dir:%d)",X_dir); |
Abdel64 | 0:fda2fbc0d37b | 119 | break; |
Abdel64 | 0:fda2fbc0d37b | 120 | case 2: X_en = 0; |
Abdel64 | 0:fda2fbc0d37b | 121 | bDir_X_label.Draw("Pause",0); |
Abdel64 | 0:fda2fbc0d37b | 122 | |
Abdel64 | 0:fda2fbc0d37b | 123 | break; |
Abdel64 | 0:fda2fbc0d37b | 124 | } |
Abdel64 | 0:fda2fbc0d37b | 125 | } |
Abdel64 | 0:fda2fbc0d37b | 126 | |
Abdel64 | 0:fda2fbc0d37b | 127 | if (FourcheLibre){ |
Abdel64 | 0:fda2fbc0d37b | 128 | |
Abdel64 | 0:fda2fbc0d37b | 129 | bStart.Draw("Ready",0); |
Abdel64 | 0:fda2fbc0d37b | 130 | |
Abdel64 | 0:fda2fbc0d37b | 131 | if (Y_en){ |
Abdel64 | 0:fda2fbc0d37b | 132 | Steppers_Y.enable(); |
Abdel64 | 0:fda2fbc0d37b | 133 | Steppers_Y.step(Y_dir,Y_speed); |
Abdel64 | 0:fda2fbc0d37b | 134 | Y_count++ ; |
Abdel64 | 0:fda2fbc0d37b | 135 | } else { |
Abdel64 | 0:fda2fbc0d37b | 136 | Steppers_Y.disable(); |
Abdel64 | 0:fda2fbc0d37b | 137 | Y_count = 0; |
Abdel64 | 0:fda2fbc0d37b | 138 | } |
Abdel64 | 0:fda2fbc0d37b | 139 | |
Abdel64 | 0:fda2fbc0d37b | 140 | if ((X_en) && (X_count < 4000)){ |
Abdel64 | 0:fda2fbc0d37b | 141 | Stepper_X.enable(); |
Abdel64 | 0:fda2fbc0d37b | 142 | Stepper_X.step(X_dir,X_speed); |
Abdel64 | 0:fda2fbc0d37b | 143 | X_count++ ; |
Abdel64 | 0:fda2fbc0d37b | 144 | } else { |
Abdel64 | 0:fda2fbc0d37b | 145 | Stepper_X.disable(); |
Abdel64 | 0:fda2fbc0d37b | 146 | X_count = 0; |
Abdel64 | 0:fda2fbc0d37b | 147 | } |
Abdel64 | 0:fda2fbc0d37b | 148 | |
Abdel64 | 0:fda2fbc0d37b | 149 | } else { |
Abdel64 | 0:fda2fbc0d37b | 150 | Steppers_Y.disable(); |
Abdel64 | 0:fda2fbc0d37b | 151 | Stepper_X.disable(); |
Abdel64 | 0:fda2fbc0d37b | 152 | bStart.Draw("Fourche !",0); |
Abdel64 | 0:fda2fbc0d37b | 153 | } |
Abdel64 | 0:fda2fbc0d37b | 154 | bCount_X_label.Draw("Count : %d",X_count); |
Abdel64 | 0:fda2fbc0d37b | 155 | bCount_Y_label.Draw("Count : %d",Y_count); |
Abdel64 | 0:fda2fbc0d37b | 156 | } |
Abdel64 | 0:fda2fbc0d37b | 157 | } |
Abdel64 | 0:fda2fbc0d37b | 158 | |
Abdel64 | 0:fda2fbc0d37b | 159 | |
Abdel64 | 0:fda2fbc0d37b | 160 |