test2017-1-13

Dependencies:   AT24C1024 DMX-STM32 mbed

Revision:
2:198becff12f4
Parent:
1:cf2f5992241c
Child:
3:dd2305e50390
--- a/main.cpp	Tue Feb 14 12:58:24 2017 +0000
+++ b/main.cpp	Wed Feb 15 11:52:10 2017 +0000
@@ -38,6 +38,7 @@
 unsigned long Acceleration1, Acceleration2;
 unsigned long param1, param2;
 unsigned long dmxInHighBit, dmxInLowBit;
+unsigned long HighBit, LowBit;
 
 bool manipulateMode1 = true; //0:手動 1:自動
 bool manipulateMode2 = true; //0:手動 1:自動
@@ -96,19 +97,15 @@
 void checkSW()
 {
     //モーター1用エンドスイッチのチェック
-    if(EndSW3.read() == 0) myLED = 1;
-    else {
+    if(EndSW3.read() == 1) {
         stepper1.stop();
         stepper1.setCurrentPosition(0);
-        myLED =0;
     }
 
     //モーター2用エンドスイッチのチェック
-    if(EndSW4.read() == 0) myLED = 1;
-    else {
+    if(EndSW4.read() == 1) {
         stepper2.stop();
         stepper2.setCurrentPosition(0);
-        myLED =0;
     }
 }
 
@@ -136,9 +133,9 @@
 
 void init()
 {
-    stepper1.setMaxSpeed(2000);
+    stepper1.setMaxSpeed(4000);
     stepper1.setAcceleration(20000);
-    stepper1.moveTo(-16000);
+    stepper1.moveTo(-20000);
 
     while(stepper1.currentPosition() != 0) {
         stepper1.run();
@@ -149,9 +146,9 @@
         stepper1.run();
     }
 
-    stepper2.setMaxSpeed(2000);
+    stepper2.setMaxSpeed(4000);
     stepper2.setAcceleration(20000);
-    stepper2.moveTo(-16000);
+    stepper2.moveTo(-20000);
 
     while(stepper2.currentPosition() != 0) {
         stepper2.run();
@@ -161,13 +158,12 @@
     while(stepper2.distanceToGo() != 0) {
         stepper2.run();
     }
-    //silence();
+    silence();
 }
 
 void checkSafeBreak()
 {
-    if(EndSW3.read() == 0) myLED = 1;
-    else {
+    if(EndSW3.read() == 1) {
         stepper1.stop();
         while(1) {
             blink();
@@ -175,8 +171,7 @@
     }
 
     //モーター2用エンドスイッチのチェック
-    if(EndSW4.read() == 0) myLED = 1;
-    else {
+    if(EndSW4.read() == 1) {
         stepper2.stop();
         while(1) {
             blink();
@@ -188,28 +183,61 @@
 void paramStore1()
 {
     //速度
-    uint8_t dt = dmx.get(2);
-    at24c1024.write(2, dt);
-    dt = dmx.get(3);
-    at24c1024.write(3, dt);
-    at24c1024.write(2, 0xf5);
+    uint8_t dt = dmx.get(DMX_Speed1_H);
+    at24c1024.write(DMX_Speed1_H, dt);
+    wait_ms(2);
+    dt = dmx.get(DMX_Speed1_L);
+    at24c1024.write(DMX_Speed1_L, dt);
     wait_ms(2);
 
     //加速度
     dt = dmx.get(DMX_Acceleration1_H);
     at24c1024.write(DMX_Acceleration1_H, dt);
+    wait_ms(2);
     dt = dmx.get(DMX_Acceleration1_L);
     at24c1024.write(DMX_Acceleration1_L, dt);
+    wait_ms(2);
 
     //最大値
     dt = dmx.get(DMX_Max1_H);
     at24c1024.write(DMX_Max1_H, dt);
+    wait_ms(2);
     dt = dmx.get(DMX_Max1_L);
     at24c1024.write(DMX_Max1_L, dt);
 
     wait_ms(5);
 }
 
+//モーター2のパラメータ保存
+void paramStore2()
+{
+    //速度
+    uint8_t dt = dmx.get(DMX_Speed2_H);
+    at24c1024.write(DMX_Speed2_H, dt);
+    wait_ms(2);
+    dt = dmx.get(DMX_Speed2_L);
+    at24c1024.write(DMX_Speed2_L, dt);
+    wait_ms(2);
+
+    //加速度
+    dt = dmx.get(DMX_Acceleration2_H);
+    at24c1024.write(DMX_Acceleration2_H, dt);
+    wait_ms(2);
+    dt = dmx.get(DMX_Acceleration2_L);
+    at24c1024.write(DMX_Acceleration2_L, dt);
+    wait_ms(2);
+
+    //最大値
+    dt = dmx.get(DMX_Max2_H);
+    at24c1024.write(DMX_Max2_H, dt);
+    wait_ms(2);
+    dt = dmx.get(DMX_Max2_L);
+    at24c1024.write(DMX_Max2_L, dt);
+
+    wait_ms(2);
+}
+
+
 //速度・加速度・最大値・オフセットの値をスライダーから取得
 void captureSliderValue()
 {
@@ -249,33 +277,48 @@
 void readROMValue1()
 {
     //速度
-    unsigned long HighBit = at24c1024.read(DMX_Speed1_H);
-    uint8_t LowBit = at24c1024.read(DMX_Speed1_L);
+    HighBit = at24c1024.read(DMX_Speed1_H);
+    LowBit = at24c1024.read(DMX_Speed1_L);
     HighBit = HighBit << 8;
-    speed1 = (unsigned long)(HighBit + LowBit);
-
+    speed1 = (long)(HighBit + LowBit);
 
     //加速度
     HighBit = at24c1024.read(DMX_Acceleration1_H);
     LowBit = at24c1024.read(DMX_Acceleration1_L);
     HighBit = HighBit << 8;
-    Acceleration1 = (unsigned long)(HighBit + LowBit);
+    Acceleration1 = (long)(HighBit + LowBit);
 
     //最大値
     HighBit = at24c1024.read(DMX_Max1_H);
     LowBit = at24c1024.read(DMX_Max1_L);
     HighBit = HighBit << 8;
-    max1 = (unsigned long)(HighBit + LowBit);
+    max1 = (long)(HighBit + LowBit);
 }
 
 
 //モーター2の 速度・加速度・オフセットの値をEEPROMから取得
 void readROMValue2()
 {
+    //速度
+    HighBit = at24c1024.read(DMX_Speed2_H);
+    LowBit = at24c1024.read(DMX_Speed2_L);
+    HighBit = HighBit << 8;
+    speed2 = (long)(HighBit + LowBit);
+
+    //加速度
+    HighBit = at24c1024.read(DMX_Acceleration2_H);
+    LowBit = at24c1024.read(DMX_Acceleration2_L);
+    HighBit = HighBit << 8;
+    Acceleration2 = (long)(HighBit + LowBit);
+
+    //最大値
+    HighBit = at24c1024.read(DMX_Max2_H);
+    LowBit = at24c1024.read(DMX_Max2_L);
+    HighBit = HighBit << 8;
+    max2 = (long)(HighBit + LowBit);
 }
 
 
-
 //操作モード切り替えボタンのチェック
 void checkManipulateButton()
 {
@@ -313,8 +356,8 @@
     } else;
 
     if(param2 == 24932) {
-        //paramStore2();
-        //blink();
+        paramStore2();
+        blink();
     } else;
 }
 
@@ -349,9 +392,8 @@
 
     myLED =1;
 
-    at24c1024.write(2, 0xf5);
-    wait_ms(2);
-
+    readROMValue1();
+    readROMValue2();
 
     while(1) {
 
@@ -375,38 +417,41 @@
 
 
         //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定
-        if(manipulateMode1 == true) {
+        if(manipulateMode1 == false) {
             captureSliderValue();
+            myLED = 0;
         }
 
         //自動モードの場合、EEPROMから値を取得、パラメーターを設定
         else {
-            readROMValue1();
+            myLED = 1;
+
         }
 
-//        //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定
-//        if(manipulateMode2 == true) {
-//            captureSliderValue();
-//        }
-//
-//        //自動モードの場合、EEPROMから値を取得、パラメーターを設定
-//        else {
-//            readROMValue2();
-//        }
+        //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定
+        if(manipulateMode2 == false) {
+            captureSliderValue();
+            myLED = 0;
+        }
+
+        //自動モードの場合、EEPROMから値を取得、パラメータを設定
+        else {
+            myLED = 1;
+        }
 
         position1 = map(position1, 0, 0xFFFF, 0, max1);
         stepper1.setMaxSpeed(speed1);
         stepper1.setAcceleration(Acceleration1);
 
-//        position2 = map(position2, 0, 0xFFFF, 0, max2);
-//        stepper2.setMaxSpeed(speed2);
-//        stepper2.setAcceleration(Acceleration2);
+        position2 = map(position2, 0, 0xFFFF, 0, max2);
+        stepper2.setMaxSpeed(speed2);
+        stepper2.setAcceleration(Acceleration2);
 
         stepper1.moveTo(position1);
-        //stepper2.moveTo(position2);
+        stepper2.moveTo(position2);
 
         checkSafeBreak();
         stepper1.run();
-        //stepper2.run();
+        stepper2.run();
     }
 }
\ No newline at end of file