test2017-1-13

Dependencies:   AT24C1024 DMX-STM32 mbed

Committer:
tomo370
Date:
Wed Feb 15 11:52:10 2017 +0000
Revision:
2:198becff12f4
Parent:
1:cf2f5992241c
Child:
3:dd2305e50390
2017_2_15_test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tomo370 0:d94213e24c2e 1 #include "mbed.h"
tomo370 0:d94213e24c2e 2 #include "AT24C1024.h"
tomo370 0:d94213e24c2e 3 #include "AccelStepper.h"
tomo370 0:d94213e24c2e 4 #include "DMX.h"
tomo370 0:d94213e24c2e 5
tomo370 0:d94213e24c2e 6 Timer t;
tomo370 1:cf2f5992241c 7 DigitalOut dmxEnable(D8); //基本L(レシーブ)に固定します
tomo370 0:d94213e24c2e 8 DMX dmx(PA_9, PA_10);
tomo370 0:d94213e24c2e 9
tomo370 1:cf2f5992241c 10 I2C i2c(D4, D5); // SDA, SCL
tomo370 1:cf2f5992241c 11 AT24C1024 at24c1024(i2c); // Atmel 1Mbit EE-PROM
tomo370 0:d94213e24c2e 12
tomo370 1:cf2f5992241c 13 AccelStepper stepper1(1, D9, D6); // step, direction
tomo370 1:cf2f5992241c 14 AccelStepper stepper2(1, D10, D7); // step, direction
tomo370 1:cf2f5992241c 15
tomo370 1:cf2f5992241c 16 //モーター1 CN0とCN1を使用
tomo370 0:d94213e24c2e 17 DigitalOut stepper1Enable(D2);
tomo370 0:d94213e24c2e 18 DigitalOut stepper1MS1(D11);
tomo370 0:d94213e24c2e 19 DigitalOut stepper1MS2(D12);
tomo370 0:d94213e24c2e 20 DigitalIn stepper1MS3(A4);
tomo370 0:d94213e24c2e 21
tomo370 1:cf2f5992241c 22 //モーター2 CN2とCN3を使用
tomo370 0:d94213e24c2e 23 DigitalOut stepper2Enable(D3);
tomo370 0:d94213e24c2e 24 DigitalOut stepper2MS1(A5);
tomo370 0:d94213e24c2e 25 DigitalOut stepper2MS2(A6);
tomo370 0:d94213e24c2e 26 DigitalOut stepper2MS3(A7);
tomo370 0:d94213e24c2e 27
tomo370 1:cf2f5992241c 28 DigitalIn EndSW1(A0); //CN4 //3端子エンドスイッチ1 予備
tomo370 1:cf2f5992241c 29 DigitalIn EndSW2(A1); //CN5 //3端子エンドスイッチ2 予備
tomo370 1:cf2f5992241c 30 DigitalIn EndSW3(A2); //CN6 //2端子エンドスイッチ1 モーター1用にする
tomo370 1:cf2f5992241c 31 DigitalIn EndSW4(A3); //CN7 //2端子エンドスイッチ2 モーター2用にする
tomo370 1:cf2f5992241c 32
tomo370 1:cf2f5992241c 33 DigitalOut myLED(LED3); //動作確認用LED
tomo370 1:cf2f5992241c 34
tomo370 1:cf2f5992241c 35 unsigned long position1, position2; //モーター1の設定位置
tomo370 1:cf2f5992241c 36 unsigned long max1, max2;
tomo370 1:cf2f5992241c 37 unsigned long speed1, speed2;
tomo370 1:cf2f5992241c 38 unsigned long Acceleration1, Acceleration2;
tomo370 1:cf2f5992241c 39 unsigned long param1, param2;
tomo370 1:cf2f5992241c 40 unsigned long dmxInHighBit, dmxInLowBit;
tomo370 2:198becff12f4 41 unsigned long HighBit, LowBit;
tomo370 1:cf2f5992241c 42
tomo370 1:cf2f5992241c 43 bool manipulateMode1 = true; //0:手動 1:自動
tomo370 1:cf2f5992241c 44 bool manipulateMode2 = true; //0:手動 1:自動
tomo370 1:cf2f5992241c 45
tomo370 1:cf2f5992241c 46
tomo370 1:cf2f5992241c 47 //モーター1のパラメーター DMXチャンネルリスト チャンネル数:12個
tomo370 1:cf2f5992241c 48 #define CH_Origin 0
tomo370 0:d94213e24c2e 49
tomo370 1:cf2f5992241c 50 #define DMX_Position1_H CH_Origin //モーター1制御用のDMX信号の始まりの値
tomo370 1:cf2f5992241c 51 #define DMX_Position1_L CH_Origin + 1
tomo370 1:cf2f5992241c 52 #define DMX_Speed1_H CH_Origin + 2
tomo370 1:cf2f5992241c 53 #define DMX_Speed1_L CH_Origin + 3
tomo370 1:cf2f5992241c 54 #define DMX_Acceleration1_H CH_Origin + 4
tomo370 1:cf2f5992241c 55 #define DMX_Acceleration1_L CH_Origin + 5
tomo370 1:cf2f5992241c 56 #define DMX_Max1_H CH_Origin + 6
tomo370 1:cf2f5992241c 57 #define DMX_Max1_L CH_Origin + 7
tomo370 1:cf2f5992241c 58 #define DMX_Offset1_H CH_Origin + 8
tomo370 1:cf2f5992241c 59 #define DMX_Offset1_L CH_Origin + 9
tomo370 1:cf2f5992241c 60 #define DMX_SaveValue1_H CH_Origin + 10
tomo370 1:cf2f5992241c 61 #define DMX_SaveValue1_L CH_Origin + 11
tomo370 1:cf2f5992241c 62 #define DMX_ParmSetMode1_H CH_Origin + 12
tomo370 1:cf2f5992241c 63 #define DMX_ParmSetMode1_L CH_Origin + 13
tomo370 0:d94213e24c2e 64
tomo370 1:cf2f5992241c 65 //モーター2のパラメーター DMXチャンネルリスト チャンネル数:12個
tomo370 1:cf2f5992241c 66 #define DMX_Position2_H CH_Origin + 16
tomo370 1:cf2f5992241c 67 #define DMX_Position2_L CH_Origin + 17
tomo370 1:cf2f5992241c 68 #define DMX_Speed2_H CH_Origin + 18
tomo370 1:cf2f5992241c 69 #define DMX_Speed2_L CH_Origin + 19
tomo370 1:cf2f5992241c 70 #define DMX_Acceleration2_H CH_Origin + 20
tomo370 1:cf2f5992241c 71 #define DMX_Acceleration2_L CH_Origin + 21
tomo370 1:cf2f5992241c 72 #define DMX_Max2_H CH_Origin + 22
tomo370 1:cf2f5992241c 73 #define DMX_Max2_L CH_Origin + 23
tomo370 1:cf2f5992241c 74 #define DMX_Offset2_H CH_Origin + 24
tomo370 1:cf2f5992241c 75 #define DMX_Offset2_L CH_Origin + 25
tomo370 1:cf2f5992241c 76 #define DMX_SaveValue2_H CH_Origin + 26
tomo370 1:cf2f5992241c 77 #define DMX_SaveValue2_L CH_Origin + 27
tomo370 1:cf2f5992241c 78 #define DMX_ParmSetMode2_H CH_Origin + 28
tomo370 1:cf2f5992241c 79 #define DMX_ParmSetMode2_L CH_Origin + 29
tomo370 1:cf2f5992241c 80
tomo370 1:cf2f5992241c 81 //map
tomo370 0:d94213e24c2e 82 long map(long x, long in_min, long in_max, long out_min, long out_max)
tomo370 0:d94213e24c2e 83 {
tomo370 0:d94213e24c2e 84 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
tomo370 0:d94213e24c2e 85 }
tomo370 0:d94213e24c2e 86
tomo370 1:cf2f5992241c 87 void blink()
tomo370 1:cf2f5992241c 88 {
tomo370 1:cf2f5992241c 89 for(int i=0; i<5; i++) {
tomo370 1:cf2f5992241c 90 myLED=0;
tomo370 1:cf2f5992241c 91 wait_ms(60);
tomo370 1:cf2f5992241c 92 myLED=1;
tomo370 1:cf2f5992241c 93 wait_ms(60);
tomo370 1:cf2f5992241c 94 }
tomo370 1:cf2f5992241c 95 }
tomo370 1:cf2f5992241c 96
tomo370 0:d94213e24c2e 97 void checkSW()
tomo370 0:d94213e24c2e 98 {
tomo370 1:cf2f5992241c 99 //モーター1用エンドスイッチのチェック
tomo370 2:198becff12f4 100 if(EndSW3.read() == 1) {
tomo370 0:d94213e24c2e 101 stepper1.stop();
tomo370 0:d94213e24c2e 102 stepper1.setCurrentPosition(0);
tomo370 0:d94213e24c2e 103 }
tomo370 1:cf2f5992241c 104
tomo370 1:cf2f5992241c 105 //モーター2用エンドスイッチのチェック
tomo370 2:198becff12f4 106 if(EndSW4.read() == 1) {
tomo370 1:cf2f5992241c 107 stepper2.stop();
tomo370 1:cf2f5992241c 108 stepper2.setCurrentPosition(0);
tomo370 1:cf2f5992241c 109 }
tomo370 0:d94213e24c2e 110 }
tomo370 0:d94213e24c2e 111
tomo370 0:d94213e24c2e 112 void silence()
tomo370 0:d94213e24c2e 113 {
tomo370 0:d94213e24c2e 114 DigitalIn stepper1MS1(D11);
tomo370 0:d94213e24c2e 115 DigitalIn stepper1MS2(D12);
tomo370 1:cf2f5992241c 116
tomo370 1:cf2f5992241c 117 DigitalIn stepper2MS1(A5);
tomo370 1:cf2f5992241c 118 DigitalIn stepper2MS2(A6);
tomo370 0:d94213e24c2e 119 }
tomo370 0:d94213e24c2e 120
tomo370 0:d94213e24c2e 121 void run()
tomo370 0:d94213e24c2e 122 {
tomo370 0:d94213e24c2e 123 DigitalOut stepper1MS1(D11);
tomo370 0:d94213e24c2e 124 DigitalOut stepper1MS2(D12);
tomo370 0:d94213e24c2e 125 stepper1MS1 = 1;
tomo370 0:d94213e24c2e 126 stepper1MS2 = 1;
tomo370 1:cf2f5992241c 127
tomo370 1:cf2f5992241c 128 DigitalOut stepper2MS1(A5);
tomo370 1:cf2f5992241c 129 DigitalOut stepper2MS2(A6);
tomo370 1:cf2f5992241c 130 stepper2MS1 = 1;
tomo370 1:cf2f5992241c 131 stepper2MS2 = 1;
tomo370 0:d94213e24c2e 132 }
tomo370 0:d94213e24c2e 133
tomo370 0:d94213e24c2e 134 void init()
tomo370 0:d94213e24c2e 135 {
tomo370 2:198becff12f4 136 stepper1.setMaxSpeed(4000);
tomo370 0:d94213e24c2e 137 stepper1.setAcceleration(20000);
tomo370 2:198becff12f4 138 stepper1.moveTo(-20000);
tomo370 0:d94213e24c2e 139
tomo370 0:d94213e24c2e 140 while(stepper1.currentPosition() != 0) {
tomo370 0:d94213e24c2e 141 stepper1.run();
tomo370 0:d94213e24c2e 142 checkSW();
tomo370 0:d94213e24c2e 143 }
tomo370 0:d94213e24c2e 144 stepper1.moveTo(500);
tomo370 0:d94213e24c2e 145 while(stepper1.distanceToGo() != 0) {
tomo370 0:d94213e24c2e 146 stepper1.run();
tomo370 0:d94213e24c2e 147 }
tomo370 1:cf2f5992241c 148
tomo370 2:198becff12f4 149 stepper2.setMaxSpeed(4000);
tomo370 1:cf2f5992241c 150 stepper2.setAcceleration(20000);
tomo370 2:198becff12f4 151 stepper2.moveTo(-20000);
tomo370 1:cf2f5992241c 152
tomo370 1:cf2f5992241c 153 while(stepper2.currentPosition() != 0) {
tomo370 1:cf2f5992241c 154 stepper2.run();
tomo370 1:cf2f5992241c 155 checkSW();
tomo370 1:cf2f5992241c 156 }
tomo370 1:cf2f5992241c 157 stepper2.moveTo(500);
tomo370 1:cf2f5992241c 158 while(stepper2.distanceToGo() != 0) {
tomo370 1:cf2f5992241c 159 stepper2.run();
tomo370 1:cf2f5992241c 160 }
tomo370 2:198becff12f4 161 silence();
tomo370 1:cf2f5992241c 162 }
tomo370 1:cf2f5992241c 163
tomo370 1:cf2f5992241c 164 void checkSafeBreak()
tomo370 1:cf2f5992241c 165 {
tomo370 2:198becff12f4 166 if(EndSW3.read() == 1) {
tomo370 1:cf2f5992241c 167 stepper1.stop();
tomo370 1:cf2f5992241c 168 while(1) {
tomo370 1:cf2f5992241c 169 blink();
tomo370 1:cf2f5992241c 170 }
tomo370 1:cf2f5992241c 171 }
tomo370 1:cf2f5992241c 172
tomo370 1:cf2f5992241c 173 //モーター2用エンドスイッチのチェック
tomo370 2:198becff12f4 174 if(EndSW4.read() == 1) {
tomo370 1:cf2f5992241c 175 stepper2.stop();
tomo370 1:cf2f5992241c 176 while(1) {
tomo370 1:cf2f5992241c 177 blink();
tomo370 1:cf2f5992241c 178 }
tomo370 1:cf2f5992241c 179 }
tomo370 1:cf2f5992241c 180 }
tomo370 1:cf2f5992241c 181
tomo370 1:cf2f5992241c 182 //モーター1のパラメータ保存
tomo370 1:cf2f5992241c 183 void paramStore1()
tomo370 1:cf2f5992241c 184 {
tomo370 1:cf2f5992241c 185 //速度
tomo370 2:198becff12f4 186 uint8_t dt = dmx.get(DMX_Speed1_H);
tomo370 2:198becff12f4 187 at24c1024.write(DMX_Speed1_H, dt);
tomo370 2:198becff12f4 188 wait_ms(2);
tomo370 2:198becff12f4 189 dt = dmx.get(DMX_Speed1_L);
tomo370 2:198becff12f4 190 at24c1024.write(DMX_Speed1_L, dt);
tomo370 1:cf2f5992241c 191 wait_ms(2);
tomo370 1:cf2f5992241c 192
tomo370 1:cf2f5992241c 193 //加速度
tomo370 1:cf2f5992241c 194 dt = dmx.get(DMX_Acceleration1_H);
tomo370 1:cf2f5992241c 195 at24c1024.write(DMX_Acceleration1_H, dt);
tomo370 2:198becff12f4 196 wait_ms(2);
tomo370 1:cf2f5992241c 197 dt = dmx.get(DMX_Acceleration1_L);
tomo370 1:cf2f5992241c 198 at24c1024.write(DMX_Acceleration1_L, dt);
tomo370 2:198becff12f4 199 wait_ms(2);
tomo370 1:cf2f5992241c 200
tomo370 1:cf2f5992241c 201 //最大値
tomo370 1:cf2f5992241c 202 dt = dmx.get(DMX_Max1_H);
tomo370 1:cf2f5992241c 203 at24c1024.write(DMX_Max1_H, dt);
tomo370 2:198becff12f4 204 wait_ms(2);
tomo370 1:cf2f5992241c 205 dt = dmx.get(DMX_Max1_L);
tomo370 1:cf2f5992241c 206 at24c1024.write(DMX_Max1_L, dt);
tomo370 1:cf2f5992241c 207
tomo370 1:cf2f5992241c 208 wait_ms(5);
tomo370 1:cf2f5992241c 209 }
tomo370 1:cf2f5992241c 210
tomo370 2:198becff12f4 211 //モーター2のパラメータ保存
tomo370 2:198becff12f4 212 void paramStore2()
tomo370 2:198becff12f4 213 {
tomo370 2:198becff12f4 214 //速度
tomo370 2:198becff12f4 215 uint8_t dt = dmx.get(DMX_Speed2_H);
tomo370 2:198becff12f4 216 at24c1024.write(DMX_Speed2_H, dt);
tomo370 2:198becff12f4 217 wait_ms(2);
tomo370 2:198becff12f4 218 dt = dmx.get(DMX_Speed2_L);
tomo370 2:198becff12f4 219 at24c1024.write(DMX_Speed2_L, dt);
tomo370 2:198becff12f4 220 wait_ms(2);
tomo370 2:198becff12f4 221
tomo370 2:198becff12f4 222 //加速度
tomo370 2:198becff12f4 223 dt = dmx.get(DMX_Acceleration2_H);
tomo370 2:198becff12f4 224 at24c1024.write(DMX_Acceleration2_H, dt);
tomo370 2:198becff12f4 225 wait_ms(2);
tomo370 2:198becff12f4 226 dt = dmx.get(DMX_Acceleration2_L);
tomo370 2:198becff12f4 227 at24c1024.write(DMX_Acceleration2_L, dt);
tomo370 2:198becff12f4 228 wait_ms(2);
tomo370 2:198becff12f4 229
tomo370 2:198becff12f4 230 //最大値
tomo370 2:198becff12f4 231 dt = dmx.get(DMX_Max2_H);
tomo370 2:198becff12f4 232 at24c1024.write(DMX_Max2_H, dt);
tomo370 2:198becff12f4 233 wait_ms(2);
tomo370 2:198becff12f4 234 dt = dmx.get(DMX_Max2_L);
tomo370 2:198becff12f4 235 at24c1024.write(DMX_Max2_L, dt);
tomo370 2:198becff12f4 236
tomo370 2:198becff12f4 237 wait_ms(2);
tomo370 2:198becff12f4 238 }
tomo370 2:198becff12f4 239
tomo370 2:198becff12f4 240
tomo370 1:cf2f5992241c 241 //速度・加速度・最大値・オフセットの値をスライダーから取得
tomo370 1:cf2f5992241c 242 void captureSliderValue()
tomo370 1:cf2f5992241c 243 {
tomo370 1:cf2f5992241c 244 dmxInHighBit = dmx.get(DMX_Speed1_H);
tomo370 1:cf2f5992241c 245 dmxInLowBit = dmx.get(DMX_Speed1_L);
tomo370 1:cf2f5992241c 246 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 247 speed1 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 248
tomo370 1:cf2f5992241c 249 dmxInHighBit = dmx.get(DMX_Speed2_H);
tomo370 1:cf2f5992241c 250 dmxInLowBit = dmx.get(DMX_Speed2_L);
tomo370 1:cf2f5992241c 251 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 252 speed2 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 253
tomo370 1:cf2f5992241c 254 dmxInHighBit = dmx.get(DMX_Acceleration1_H);
tomo370 1:cf2f5992241c 255 dmxInLowBit = dmx.get(DMX_Acceleration1_L);
tomo370 1:cf2f5992241c 256 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 257 Acceleration1 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 258
tomo370 1:cf2f5992241c 259 dmxInHighBit = dmx.get(DMX_Acceleration2_H);
tomo370 1:cf2f5992241c 260 dmxInLowBit = dmx.get(DMX_Acceleration2_L);
tomo370 1:cf2f5992241c 261 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 262 Acceleration2 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 263
tomo370 1:cf2f5992241c 264 dmxInHighBit = dmx.get(DMX_Max1_H);
tomo370 1:cf2f5992241c 265 dmxInLowBit = dmx.get(DMX_Max1_L);
tomo370 1:cf2f5992241c 266 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 267 max1 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 268
tomo370 1:cf2f5992241c 269 dmxInHighBit = dmx.get(DMX_Max2_H);
tomo370 1:cf2f5992241c 270 dmxInLowBit = dmx.get(DMX_Max2_L);
tomo370 1:cf2f5992241c 271 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 272 max2 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 273 }
tomo370 0:d94213e24c2e 274
tomo370 0:d94213e24c2e 275
tomo370 1:cf2f5992241c 276 //モーター1の 速度・加速度・オフセットの値をEEPROMから取得
tomo370 1:cf2f5992241c 277 void readROMValue1()
tomo370 1:cf2f5992241c 278 {
tomo370 1:cf2f5992241c 279 //速度
tomo370 2:198becff12f4 280 HighBit = at24c1024.read(DMX_Speed1_H);
tomo370 2:198becff12f4 281 LowBit = at24c1024.read(DMX_Speed1_L);
tomo370 1:cf2f5992241c 282 HighBit = HighBit << 8;
tomo370 2:198becff12f4 283 speed1 = (long)(HighBit + LowBit);
tomo370 1:cf2f5992241c 284
tomo370 1:cf2f5992241c 285 //加速度
tomo370 1:cf2f5992241c 286 HighBit = at24c1024.read(DMX_Acceleration1_H);
tomo370 1:cf2f5992241c 287 LowBit = at24c1024.read(DMX_Acceleration1_L);
tomo370 1:cf2f5992241c 288 HighBit = HighBit << 8;
tomo370 2:198becff12f4 289 Acceleration1 = (long)(HighBit + LowBit);
tomo370 1:cf2f5992241c 290
tomo370 1:cf2f5992241c 291 //最大値
tomo370 1:cf2f5992241c 292 HighBit = at24c1024.read(DMX_Max1_H);
tomo370 1:cf2f5992241c 293 LowBit = at24c1024.read(DMX_Max1_L);
tomo370 1:cf2f5992241c 294 HighBit = HighBit << 8;
tomo370 2:198becff12f4 295 max1 = (long)(HighBit + LowBit);
tomo370 1:cf2f5992241c 296 }
tomo370 1:cf2f5992241c 297
tomo370 1:cf2f5992241c 298
tomo370 1:cf2f5992241c 299 //モーター2の 速度・加速度・オフセットの値をEEPROMから取得
tomo370 1:cf2f5992241c 300 void readROMValue2()
tomo370 1:cf2f5992241c 301 {
tomo370 2:198becff12f4 302 //速度
tomo370 2:198becff12f4 303 HighBit = at24c1024.read(DMX_Speed2_H);
tomo370 2:198becff12f4 304 LowBit = at24c1024.read(DMX_Speed2_L);
tomo370 2:198becff12f4 305 HighBit = HighBit << 8;
tomo370 2:198becff12f4 306 speed2 = (long)(HighBit + LowBit);
tomo370 2:198becff12f4 307
tomo370 2:198becff12f4 308 //加速度
tomo370 2:198becff12f4 309 HighBit = at24c1024.read(DMX_Acceleration2_H);
tomo370 2:198becff12f4 310 LowBit = at24c1024.read(DMX_Acceleration2_L);
tomo370 2:198becff12f4 311 HighBit = HighBit << 8;
tomo370 2:198becff12f4 312 Acceleration2 = (long)(HighBit + LowBit);
tomo370 2:198becff12f4 313
tomo370 2:198becff12f4 314 //最大値
tomo370 2:198becff12f4 315 HighBit = at24c1024.read(DMX_Max2_H);
tomo370 2:198becff12f4 316 LowBit = at24c1024.read(DMX_Max2_L);
tomo370 2:198becff12f4 317 HighBit = HighBit << 8;
tomo370 2:198becff12f4 318 max2 = (long)(HighBit + LowBit);
tomo370 0:d94213e24c2e 319 }
tomo370 0:d94213e24c2e 320
tomo370 0:d94213e24c2e 321
tomo370 1:cf2f5992241c 322 //操作モード切り替えボタンのチェック
tomo370 1:cf2f5992241c 323 void checkManipulateButton()
tomo370 1:cf2f5992241c 324 {
tomo370 1:cf2f5992241c 325 dmxInHighBit = dmx.get(DMX_ParmSetMode1_H);
tomo370 1:cf2f5992241c 326 dmxInLowBit = dmx.get(DMX_ParmSetMode1_L);
tomo370 1:cf2f5992241c 327 if(dmxInHighBit == 102 && dmxInLowBit == 255) {
tomo370 1:cf2f5992241c 328 manipulateMode1 = !manipulateMode1;
tomo370 1:cf2f5992241c 329 blink();
tomo370 1:cf2f5992241c 330 }
tomo370 1:cf2f5992241c 331
tomo370 1:cf2f5992241c 332 dmxInHighBit = dmx.get(DMX_ParmSetMode2_H);
tomo370 1:cf2f5992241c 333 dmxInLowBit = dmx.get(DMX_ParmSetMode2_L);
tomo370 1:cf2f5992241c 334 if(dmxInHighBit == 102 && dmxInLowBit == 255) {
tomo370 1:cf2f5992241c 335 manipulateMode2 = !manipulateMode2;
tomo370 1:cf2f5992241c 336 blink();
tomo370 1:cf2f5992241c 337 }
tomo370 1:cf2f5992241c 338 }
tomo370 1:cf2f5992241c 339
tomo370 1:cf2f5992241c 340 //書き込みボタンのチェック
tomo370 1:cf2f5992241c 341 void checkWriteButton()
tomo370 1:cf2f5992241c 342 {
tomo370 1:cf2f5992241c 343 dmxInHighBit = dmx.get(DMX_SaveValue1_H);
tomo370 1:cf2f5992241c 344 dmxInLowBit = dmx.get(DMX_SaveValue1_L);
tomo370 1:cf2f5992241c 345 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 346 param1 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 347
tomo370 1:cf2f5992241c 348 dmxInHighBit = dmx.get(DMX_SaveValue2_H);
tomo370 1:cf2f5992241c 349 dmxInLowBit = dmx.get(DMX_SaveValue2_L);
tomo370 1:cf2f5992241c 350 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 351 param2 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 352
tomo370 1:cf2f5992241c 353 if(param1 == 24932) {
tomo370 1:cf2f5992241c 354 paramStore1();
tomo370 1:cf2f5992241c 355 blink();
tomo370 1:cf2f5992241c 356 } else;
tomo370 1:cf2f5992241c 357
tomo370 1:cf2f5992241c 358 if(param2 == 24932) {
tomo370 2:198becff12f4 359 paramStore2();
tomo370 2:198becff12f4 360 blink();
tomo370 1:cf2f5992241c 361 } else;
tomo370 1:cf2f5992241c 362 }
tomo370 1:cf2f5992241c 363
tomo370 1:cf2f5992241c 364
tomo370 0:d94213e24c2e 365 int main()
tomo370 0:d94213e24c2e 366 {
tomo370 1:cf2f5992241c 367 //モーター1と2のコンフィギュレーション
tomo370 0:d94213e24c2e 368 stepper1MS1 = 1;
tomo370 0:d94213e24c2e 369 stepper1MS2 = 1;
tomo370 0:d94213e24c2e 370 stepper1Enable = 0;
tomo370 0:d94213e24c2e 371
tomo370 1:cf2f5992241c 372 stepper2MS1 = 1;
tomo370 1:cf2f5992241c 373 stepper2MS2 = 1;
tomo370 1:cf2f5992241c 374 stepper2Enable = 0;
tomo370 1:cf2f5992241c 375
tomo370 0:d94213e24c2e 376 t.start();
tomo370 0:d94213e24c2e 377
tomo370 0:d94213e24c2e 378 dmxEnable = 0; //0:receiver 1:sender
tomo370 0:d94213e24c2e 379
tomo370 0:d94213e24c2e 380 stepper1.setCurrentPosition(-1);
tomo370 1:cf2f5992241c 381 stepper2.setCurrentPosition(-1);
tomo370 0:d94213e24c2e 382
tomo370 0:d94213e24c2e 383 init();
tomo370 0:d94213e24c2e 384
tomo370 0:d94213e24c2e 385 stepper1.setMaxSpeed(25000);
tomo370 0:d94213e24c2e 386 stepper1.setAcceleration(30000);
tomo370 0:d94213e24c2e 387 stepper1.setCurrentPosition(0);
tomo370 0:d94213e24c2e 388
tomo370 1:cf2f5992241c 389 stepper2.setMaxSpeed(25000);
tomo370 1:cf2f5992241c 390 stepper2.setAcceleration(30000);
tomo370 1:cf2f5992241c 391 stepper2.setCurrentPosition(0);
tomo370 1:cf2f5992241c 392
tomo370 1:cf2f5992241c 393 myLED =1;
tomo370 1:cf2f5992241c 394
tomo370 2:198becff12f4 395 readROMValue1();
tomo370 2:198becff12f4 396 readROMValue2();
tomo370 0:d94213e24c2e 397
tomo370 0:d94213e24c2e 398 while(1) {
tomo370 0:d94213e24c2e 399
tomo370 1:cf2f5992241c 400 //操作モード切り替えボタンのチェック
tomo370 1:cf2f5992241c 401 checkManipulateButton();
tomo370 1:cf2f5992241c 402
tomo370 1:cf2f5992241c 403 //書き込みボタンチェック
tomo370 1:cf2f5992241c 404 checkWriteButton();
tomo370 0:d94213e24c2e 405
tomo370 1:cf2f5992241c 406 //モーター1の目標位置をスライダーから取得
tomo370 1:cf2f5992241c 407 dmxInHighBit = dmx.get(DMX_Position1_H);
tomo370 1:cf2f5992241c 408 dmxInLowBit = dmx.get(DMX_Position1_L);
tomo370 1:cf2f5992241c 409 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 410 position1 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 0:d94213e24c2e 411
tomo370 1:cf2f5992241c 412 //モーター1の目標位置をスライダーから取得
tomo370 1:cf2f5992241c 413 dmxInHighBit = dmx.get(DMX_Position2_H);
tomo370 1:cf2f5992241c 414 dmxInLowBit = dmx.get(DMX_Position2_L);
tomo370 1:cf2f5992241c 415 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 416 position2 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 0:d94213e24c2e 417
tomo370 0:d94213e24c2e 418
tomo370 1:cf2f5992241c 419 //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定
tomo370 2:198becff12f4 420 if(manipulateMode1 == false) {
tomo370 1:cf2f5992241c 421 captureSliderValue();
tomo370 2:198becff12f4 422 myLED = 0;
tomo370 1:cf2f5992241c 423 }
tomo370 0:d94213e24c2e 424
tomo370 1:cf2f5992241c 425 //自動モードの場合、EEPROMから値を取得、パラメーターを設定
tomo370 1:cf2f5992241c 426 else {
tomo370 2:198becff12f4 427 myLED = 1;
tomo370 2:198becff12f4 428
tomo370 1:cf2f5992241c 429 }
tomo370 0:d94213e24c2e 430
tomo370 2:198becff12f4 431 //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定
tomo370 2:198becff12f4 432 if(manipulateMode2 == false) {
tomo370 2:198becff12f4 433 captureSliderValue();
tomo370 2:198becff12f4 434 myLED = 0;
tomo370 2:198becff12f4 435 }
tomo370 2:198becff12f4 436
tomo370 2:198becff12f4 437 //自動モードの場合、EEPROMから値を取得、パラメータを設定
tomo370 2:198becff12f4 438 else {
tomo370 2:198becff12f4 439 myLED = 1;
tomo370 2:198becff12f4 440 }
tomo370 1:cf2f5992241c 441
tomo370 1:cf2f5992241c 442 position1 = map(position1, 0, 0xFFFF, 0, max1);
tomo370 1:cf2f5992241c 443 stepper1.setMaxSpeed(speed1);
tomo370 1:cf2f5992241c 444 stepper1.setAcceleration(Acceleration1);
tomo370 1:cf2f5992241c 445
tomo370 2:198becff12f4 446 position2 = map(position2, 0, 0xFFFF, 0, max2);
tomo370 2:198becff12f4 447 stepper2.setMaxSpeed(speed2);
tomo370 2:198becff12f4 448 stepper2.setAcceleration(Acceleration2);
tomo370 1:cf2f5992241c 449
tomo370 1:cf2f5992241c 450 stepper1.moveTo(position1);
tomo370 2:198becff12f4 451 stepper2.moveTo(position2);
tomo370 1:cf2f5992241c 452
tomo370 1:cf2f5992241c 453 checkSafeBreak();
tomo370 1:cf2f5992241c 454 stepper1.run();
tomo370 2:198becff12f4 455 stepper2.run();
tomo370 1:cf2f5992241c 456 }
tomo370 1:cf2f5992241c 457 }