From 729171bafe1ca5aa19c2dcc71d19f27cf1ad531a Mon Sep 17 00:00:00 2001 From: medina5 Date: Wed, 14 Jan 2026 23:52:06 +0100 Subject: [PATCH] 18 --- .devcontainer/nodered/flows.json | 155 ++++++++++++++++++++++--------- 17.md | 56 +++++++++++ 18.md | 53 ++--------- autom.cpp | 42 ++++----- main.cpp | 124 +++++++++++-------------- 5 files changed, 247 insertions(+), 183 deletions(-) create mode 100644 17.md diff --git a/.devcontainer/nodered/flows.json b/.devcontainer/nodered/flows.json index f380cd3..9701ef3 100644 --- a/.devcontainer/nodered/flows.json +++ b/.devcontainer/nodered/flows.json @@ -652,7 +652,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s0", - "func": "msg.payload = Number(msg.payload.s0) ? \"🟩\" : \"🟥\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[0]) ? \"🟩\" : \"🟥\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -672,7 +672,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s1", - "func": "msg.payload = Number(msg.payload.s1) ? \"🟩\" : \"🟥\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[1]\n) ? \"🟩\" : \"🟥\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -692,7 +692,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s2", - "func": "msg.payload = Number(msg.payload.s2) ? \"🟩\" : \"🟥\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[2]) ? \"🟩\" : \"🟥\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -832,7 +832,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s3", - "func": "msg.payload = Number(msg.payload.s3) ? \"🟩\" : \"🟥\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[3]) ? \"🟩\" : \"🟥\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -852,7 +852,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s4", - "func": "msg.payload = Number(msg.payload.s4) ? \"🟩\" : \"🟥\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[4]) ? \"🟩\" : \"🟥\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -872,7 +872,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s5", - "func": "msg.payload = Number(msg.payload.s5) ? \"🟩\" : \"🟥\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[5]) ? \"🟩\" : \"🟥\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -892,7 +892,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s6", - "func": "msg.payload = Number(msg.payload.s6) ? \"🟩\" : \"🟥\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[6]) ? \"🟩\" : \"🟥\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -912,7 +912,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s7", - "func": "msg.payload = Number(msg.payload.s7) ? \"🟩\" : \"🟥\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[7]) ? \"🟩\" : \"🟥\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -932,7 +932,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "reset", - "func": "flow.set(\"i0\", 0);\nflow.set(\"i1\", 0);\nflow.set(\"i2\", 0);\nflow.set(\"i3\", 0);\nflow.set(\"i4\", 0);\nflow.set(\"i5\", 0);\nflow.set(\"i6\", 0);\nflow.set(\"i7\", 0);\n\nglobal.set(\"a0\", 0);\nglobal.set(\"a1\", 0);\nglobal.set(\"a2\", 0);\nglobal.set(\"a3\", 0);\nglobal.set(\"a4\", 0);\nglobal.set(\"a5\", 0);\nglobal.set(\"a6\", 0);\nglobal.set(\"a7\", 0);\n\nglobal.set(\"m0\", 0);\nglobal.set(\"m1\", 0);\nglobal.set(\"m2\", 0);\nglobal.set(\"m3\", 0);\n\nglobal.set(\"p0\", 0);\n\nglobal.set(\"v0\", 0);\n\nglobal.set(\"c0\", 1);\nglobal.set(\"c1\", 1);\nglobal.set(\"c2\", 0);\nglobal.set(\"c3\", 0);\nglobal.set(\"c4\", 0);\nglobal.set(\"c5\", 0);\nglobal.set(\"c6\", 0);\nglobal.set(\"c7\", 0);\n\nglobal.set(\"s8\", 0);\nglobal.set(\"s9\", 0);\n\nglobal.set(\"flag0\", 0);\n\nmsg.payload = false;\n\nreturn msg;", + "func": "flow.set(\"i0\", 0);\nflow.set(\"i1\", 0);\nflow.set(\"i2\", 0);\nflow.set(\"i3\", 0);\nflow.set(\"i4\", 0);\nflow.set(\"i5\", 0);\nflow.set(\"i6\", 0);\nflow.set(\"i7\", 0);\n\nglobal.set(\"a0\", 0);\nglobal.set(\"a1\", 0);\nglobal.set(\"a2\", 0);\nglobal.set(\"a3\", 0);\nglobal.set(\"a4\", 0);\nglobal.set(\"a5\", 0);\nglobal.set(\"a6\", 0);\nglobal.set(\"a7\", 0);\n\nglobal.set(\"m0\", 0);\nglobal.set(\"m1\", 0);\nglobal.set(\"m2\", 0);\nglobal.set(\"m3\", 0);\n\nglobal.set(\"p0\", 0);\n\nglobal.set(\"v0\", 0);\n\nglobal.set(\"c0\", 1);\nglobal.set(\"c1\", 0);\nglobal.set(\"c2\", 1);\nglobal.set(\"c3\", 0);\nglobal.set(\"c4\", 0);\nglobal.set(\"c5\", 0);\nglobal.set(\"c6\", 0);\nglobal.set(\"c7\", 0);\n\nglobal.set(\"s8\", 0);\nglobal.set(\"s9\", 0);\n\nglobal.set(\"flag0\", 0);\n\nmsg.payload = false;\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -2025,7 +2025,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s8 🟢", - "func": "msg.payload = Number(msg.payload.s8) == 1 ? \"🟢\" : \"\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[8]) == 1 ? \"🟢\" : \"\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -2045,7 +2045,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s8 🟠", - "func": "msg.payload = Number(msg.payload.s8) == 2 ? \"🟠\" : \"\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[8]) == 2 ? \"🟠\" : \"\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -2065,7 +2065,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s8 🔴", - "func": "msg.payload = Number(msg.payload.s8) == 3 ? \"🔴\" : \"\";\n\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[8]) == 3 ? \"🔴\" : \"\";\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -2786,7 +2786,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s9 🠙", - "func": "msg.ui_update = msg.payload.s9 < 0 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\n\nif (msg.payload.s9 > 0)\n global.set(\"s9\", 1);\nelse if (msg.payload.s9 < 0)\n global.set(\"s9\", -1);\nelse \n global.set(\"s9\", 0);\n\nreturn msg;", + "func": "msg.ui_update = msg.payload.sorties[9] > 0 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\n\nif (msg.payload.sorties[9] > 0)\n global.set(\"s9\", 1);\nelse if (msg.payload.sorties[9] < 0)\n global.set(\"s9\", -1);\nelse \n global.set(\"s9\", 0);\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -2806,7 +2806,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s9 🠛", - "func": "msg.ui_update = msg.payload.s9 > 0 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\nreturn msg;", + "func": "msg.ui_update = msg.payload.sorties[9] < 0 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -2850,7 +2850,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s10", - "func": "msg.payload = Number(msg.payload.s10);\nreturn msg;", + "func": "msg.payload = Number(msg.payload.sorties[10]);\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -2910,7 +2910,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "reset s", - "func": "msg.payload = {\n \"s0\": 0,\n \"s1\": 0,\n \"s2\": 0,\n \"s3\": 0,\n \"s4\": 0,\n \"s5\": 0,\n \"s6\": 0,\n \"s7\": 0,\n \"s8\": 0,\n \"s9\": 0,\n \"s10\": 0,\n \"s11\": 0,\n \"m0\": 0,\n \"m1\": 0,\n \"m2\": 0,\n \"m3\": 0\n}\n\nreturn msg;", + "func": "msg.payload = {\n sorties: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n actionneurs: [0, 0, 0, 0, 0, 0, 0, 0],\n \"m0\": 0,\n \"m1\": 0,\n \"m2\": 0,\n \"m3\": 0\n}\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -2963,7 +2963,8 @@ "100a58f1b621c53a", "29d203e016b983f6", "e41bd818da135c8c", - "e7b6444f18166784" + "e7b6444f18166784", + "c35fc0f16cdcd248" ] ] }, @@ -3103,7 +3104,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "a0", - "func": "msg.payload = Number(msg.payload.a0) ? \"🟩\" : \"🟥\";\nreturn msg;", + "func": "msg.payload = Number(msg.payload.actionneurs[0]) ? \"🟩\" : \"🟥\";\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3123,7 +3124,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "a1", - "func": "msg.payload = Number(msg.payload.a1) ? \"🟩\" : \"🟥\";\nreturn msg;", + "func": "msg.payload = Number(msg.payload.actionneurs[1]) ? \"🟩\" : \"🟥\";\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3143,7 +3144,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "a2", - "func": "msg.payload = Number(msg.payload.a2) ? \"🟩\" : \"🟥\";\nreturn msg;", + "func": "msg.payload = Number(msg.payload.actionneurs[2]) ? \"🟩\" : \"🟥\";\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3158,12 +3159,56 @@ ] ] }, + { + "id": "5f29ee2b49dce0b4", + "type": "ui-text", + "z": "86a34ee77bf6db10", + "group": "02fab8cbf37e2bb7", + "order": 10, + "width": 0, + "height": 0, + "name": "", + "label": "", + "format": "{{msg.payload}}", + "layout": "row-spread", + "style": true, + "font": "", + "fontSize": "28", + "color": "#717171", + "wrapText": false, + "className": "", + "value": "payload", + "valueType": "msg", + "x": 870, + "y": 2060, + "wires": [] + }, + { + "id": "c35fc0f16cdcd248", + "type": "function", + "z": "86a34ee77bf6db10", + "name": "s11 🏁", + "func": "if (Number(msg.payload.sorties[11]) == 1) {\n msg.payload = \"🏁\";\n}\nelse {\n msg.payload = \"\";\n}\n\nreturn msg;", + "outputs": 1, + "timeout": 0, + "noerr": 0, + "initialize": "", + "finalize": "", + "libs": [], + "x": 690, + "y": 2060, + "wires": [ + [ + "5f29ee2b49dce0b4" + ] + ] + }, { "id": "cefd0feeeaf4227c", "type": "function", "z": "b5e17af18ea9731a", "name": "a0", - "func": "global.set(\"a0\", Number(msg.payload.a0));\nmsg.payload = msg.payload.a0;\nreturn msg;", + "func": "msg.payload = msg.payload.actionneurs && msg.payload.actionneurs[0];\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3342,7 +3387,7 @@ "type": "function", "z": "b5e17af18ea9731a", "name": "a1", - "func": "global.set(\"a1\", Number(msg.payload.a1));\nmsg.payload = msg.payload.a1;\nreturn msg;", + "func": "msg.payload = msg.payload.actionneurs && msg.payload.actionneurs[1];\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3417,8 +3462,8 @@ "id": "4aa7b6db9b990fa0", "type": "function", "z": "b5e17af18ea9731a", - "name": "c2 = 0", - "func": "global.set(\"c2\", 0);\nreturn msg;", + "name": "c3 = 0", + "func": "global.set(\"c3\", 0);\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3435,8 +3480,8 @@ "id": "57189f4df55ec290", "type": "function", "z": "b5e17af18ea9731a", - "name": "c1 = 0", - "func": "global.set(\"c1\", 0);\nreturn msg;", + "name": "c2 = 0", + "func": "global.set(\"c2\", 0);\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3478,8 +3523,8 @@ "id": "fb3f9295012fd03e", "type": "function", "z": "b5e17af18ea9731a", - "name": "c2 = 1", - "func": "global.set(\"c2\", 1);\nreturn msg;", + "name": "c3 = 1", + "func": "global.set(\"c3\", 1);\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3521,8 +3566,8 @@ "id": "aa06273eb1db7d1a", "type": "function", "z": "b5e17af18ea9731a", - "name": "c1 = 1", - "func": "global.set(\"c1\", 1);\nreturn msg;", + "name": "c2 = 1", + "func": "global.set(\"c2\", 1);\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3540,7 +3585,7 @@ "type": "function", "z": "b5e17af18ea9731a", "name": "a2", - "func": "global.set(\"a2\", Number(msg.payload.a2));\nmsg.payload = msg.payload.a2;\nreturn msg;", + "func": "msg.payload = msg.payload.actionneurs && msg.payload.actionneurs[2];\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3639,7 +3684,7 @@ "type": "function", "z": "b5e17af18ea9731a", "name": "c3 = 1", - "func": "global.set(\"c3\", 1);\nglobal.set(\"c6\", 0);\n\nif (Number(global.get(\"flag0\")) == 1) {\n global.set(\"flag0\", 0);\n global.set(\"c5\", 1);\n}\n\nreturn msg;", + "func": "global.set(\"c5\", 1);\nglobal.set(\"c6\", 0);\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3656,8 +3701,8 @@ "id": "70967b168ac9ceb6", "type": "function", "z": "b5e17af18ea9731a", - "name": "c3 = 0", - "func": "global.set(\"c3\", 0);\nreturn msg;", + "name": "c5 = 0", + "func": "global.set(\"c5\", 0);\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3675,7 +3720,7 @@ "type": "function", "z": "b5e17af18ea9731a", "name": "a3", - "func": "global.set(\"a3\", Number(msg.payload.a3));\nmsg.payload = msg.payload.a3;\nreturn msg;", + "func": "msg.payload = msg.payload.actionneurs && msg.payload.actionneurs[3];\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -3738,7 +3783,7 @@ "wires": [ [], [ - "a4029ba85e639676" + "a6d6f34770814538" ] ] }, @@ -3746,16 +3791,16 @@ "id": "13d74fea2023a497", "type": "function", "z": "b5e17af18ea9731a", - "name": "c5 = 0", - "func": "global.set(\"c5\", 0);\nreturn msg;", + "name": "c7 = 0", + "func": "global.set(\"c7\", 0);\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], - "x": 1130, - "y": 720, + "x": 1230, + "y": 740, "wires": [ [] ] @@ -3966,7 +4011,7 @@ "z": "b5e17af18ea9731a", "name": "soufflage", "pauseType": "delay", - "timeout": "500", + "timeout": "1000", "timeoutUnits": "milliseconds", "rate": "1", "nbRateUnits": "1", @@ -3977,8 +4022,8 @@ "drop": false, "allowrate": false, "outputs": 1, - "x": 960, - "y": 720, + "x": 1060, + "y": 740, "wires": [ [ "13d74fea2023a497" @@ -3994,7 +4039,7 @@ "397735dd2560f7cf" ], "x": 215, - "y": 420, + "y": 440, "wires": [ [ "cefd0feeeaf4227c", @@ -4070,7 +4115,7 @@ "type": "debug", "z": "b5e17af18ea9731a", "name": "a3", - "active": false, + "active": true, "tosidebar": true, "console": false, "tostatus": false, @@ -4082,6 +4127,26 @@ "y": 600, "wires": [] }, + { + "id": "a6d6f34770814538", + "type": "function", + "z": "b5e17af18ea9731a", + "name": "c7 = 1", + "func": "if (Number(global.get(\"flag0\")) == 1) {\n global.set(\"flag0\", 0);\n global.set(\"c7\", 1);\n}\n\nreturn msg;", + "outputs": 1, + "timeout": 0, + "noerr": 0, + "initialize": "", + "finalize": "", + "libs": [], + "x": 890, + "y": 740, + "wires": [ + [ + "a4029ba85e639676" + ] + ] + }, { "id": "978ded7ba3456f70", "type": "link in", diff --git a/17.md b/17.md new file mode 100644 index 0000000..1ae8f15 --- /dev/null +++ b/17.md @@ -0,0 +1,56 @@ + /* + int etape_suivante = etape; + int etape_suivante2 = etape_2; + + if (etape == 0 && b6_frontmontant == 1) { + etape_suivante = 1; + } + + if (etape == 1 && b6_frontmontant == 1) { + etape_suivante = 0; + } + + if (etape_2 == 0 && b7_frontmontant == 1) + { + etape_suivante2 = 1; + } + + if (etape_2 == 1 && b7_frontmontant == 1) + { + etape_suivante2 = 0; + } + + etape = etape_suivante; + etape_2 = etape_suivante2; + + m0 = etape == 1; + m1 = etape_2 == 1; + */ + + + if (b6_frontmontant) { + m0 = !m0; + } + + if (b7_frontmontant) { + m1 = !m1; + } + + + if (abs(p0 - v0) < 3) { + m0 = m1 = 0; + + } else { + + if (p0 < v0) + { + m0 = 1; + m1 = 0; + } + + if (p0 > v0) + { + m0 = 0; + m1 = 1; + } + } diff --git a/18.md b/18.md index 2804112..fb78b9a 100644 --- a/18.md +++ b/18.md @@ -1,58 +1,25 @@ - ci = (c0 == 1 && c1 == 1 && c2 == 0 && c3 == 0 && c5 == 0 && c6 == 0); - if (marche_frontmontant == 1 && ci == 1) { - mode_auto = 1; - etape = 1; - } + if (arret_frontdescedant == 1) { mode_auto = 0; } - if (etape == 1 && c6 == 1) { - etape = 2; - } - - if (etape == 2 && c2 == 1) { - etape = 3; - } - - if (etape == 3 && tempo == 0) { - tempo = millis(); - } - - if (etape == 3 && millis() > tempo + 3000) { - etape = 4; - tempo = 0; - } - - if (etape == 4 && c1 == 1) { - etape = 5; - } - - if (etape == 5 && c3 == 1) { - etape = 6; - } - - if (etape == 6 && c5_frontdescendant == 1) { - etape = 1; - } + s0 = mode_auto == 1; if (ci && mode_auto == 0) { s8 = 1; - } else if (ci && mode_auto == 1) { + } + else if (ci && mode_auto == 1) { s8 = 2; - } else if (mode_auto) { + } + else if (mode_auto) + { s8 = 3; - } else { + } + else + { s8 = 0; } - - s10 = etape; - - a0 = (etape == 1); - a1 = (etape == 2 || etape == 3); - a2 = (etape == 5); - a3 = (etape == 6); diff --git a/autom.cpp b/autom.cpp index 29dff54..57a5e98 100644 --- a/autom.cpp +++ b/autom.cpp @@ -111,17 +111,19 @@ public: if (j.empty()) return; - if (j.contains("marche")) + if (j.contains("marche")) { marche = j["marche"].get() != 0; + } - if (j.contains("arret")) + if (j.contains("arret")) { arret = j["arret"].get() != 0; + } - if (j.contains("reset")) + if (j.contains("reset")) { reset = j["reset"].get() != 0; + } - if (j.contains("b0") && j["b0"].is_number()) - { + if (j.contains("b0") && j["b0"].is_number()) { bouton[0] = b0 = j["b0"].get(); } if (j.contains("b1") && j["b1"].is_number()) @@ -228,32 +230,22 @@ void mqtt_open(mqtt::async_client *client) void mqtt_send(mqtt::async_client *client) { json obj = { - {"s0", s0}, - {"s1", s1}, - {"s2", s2}, - {"s3", s3}, - {"s4", s4}, - {"s5", s5}, - {"s6", s6}, - {"s7", s7}, {"m0", m0}, {"m1", m1}, {"m2", m2}, {"m3", m3}, - {"a0", a0}, - {"a1", a1}, - {"a2", a2}, - {"a3", a3}, - {"a4", a4}, - {"a5", a5}, - {"a6", a6}, - {"a7", a7}, - {"s8", s8}, - {"s9", s9}, - {"s10", s10}, - {"s11", s11}, }; + obj["c"] = json::array(); + for (int i = 0; i < 8; ++i) { + obj["actionneurs"].push_back(actionneur[i]); + } + + obj["sorties"] = json::array(); + for (int i = 0; i < 12; ++i) { + obj["sorties"].push_back(sortie[i]); + } + std::string payload = obj.dump(); auto msg = mqtt::make_message("geii/out", payload); msg->set_qos(1); diff --git a/main.cpp b/main.cpp index 624c022..007d7ee 100644 --- a/main.cpp +++ b/main.cpp @@ -13,23 +13,6 @@ int bouton_precedent[8]; int bouton_frontmontant[8]; int bouton_frontdescendant[8]; -int b0_precedent = 0; -int b0_frontmontant = 0; -int b1_precedent = 0; -int b1_frontmontant = 0; -int b2_precedent = 0; -int b2_frontmontant = 0; -int b3_precedent = 0; -int b3_frontmontant = 0; -int b4_precedent = 0; -int b4_frontmontant = 0; -int b5_precedent = 0; -int b5_frontmontant = 0; -int b6_precedent = 0; -int b6_frontmontant = 0; -int b7_precedent = 0; -int b7_frontmontant = 0; - int cycle = 0; long unsigned tempo = 0; int compteur = 0; @@ -41,10 +24,8 @@ int mode_manu = 0; int etape = 0; int etape_2 = 0; -int c5_frontdescendant = 0; -int c5_precedent = 0; - - +int c7_frontdescendant = 0; +int c7_precedent = 0; int main() { @@ -63,77 +44,80 @@ int main() void process() { - // Détection du front montant (état courant supérieur à l'état précédent) + // Détection des fronts + // front montant (état courant supérieur à l'état précédent) + // front descendant (état courant inférieur à l'état précédent) + // **************************************************************** + marche_frontmontant = marche > marche_precedent; + arret_frontdescedant = arret < arret_precedent; for(int i = 0; i < 8 ; i++) { bouton_frontmontant[i] = bouton[i] > bouton_precedent[i]; bouton_frontdescendant[i] = bouton[i] < bouton_precedent[i]; } - marche_frontmontant = marche > marche_precedent; - arret_frontdescedant = arret < arret_precedent; + /* **************************************************************** - /* - int etape_suivante = etape; - int etape_suivante2 = etape_2; + **************************************************************** */ + c7_frontdescendant = capteur[7] < c7_precedent; - if (etape == 0 && b6_frontmontant == 1) { - etape_suivante = 1; - } + ci = (capteur[0] == 1 && capteur[2] == 1 && capteur[3] == 0 && capteur[5] == 0 && capteur[6] == 0 && capteur[7] == 0); - if (etape == 1 && b6_frontmontant == 1) { - etape_suivante = 0; - } - - if (etape_2 == 0 && b7_frontmontant == 1) + if (ci == 1 && marche_frontmontant == 1) { - etape_suivante2 = 1; + mode_auto = 1; + etape = 1; } - if (etape_2 == 1 && b7_frontmontant == 1) + if (etape == 1 && capteur[0] == 0 && capteur[6] == 1) { - etape_suivante2 = 0; + etape = 2; } - etape = etape_suivante; - etape_2 = etape_suivante2; - - m0 = etape == 1; - m1 = etape_2 == 1; - */ - - - if (b6_frontmontant) { - m0 = !m0; + if (etape == 2 && capteur[3] == 1) + { + etape = 3; } - if (b7_frontmontant) { - m1 = !m1; + if (etape == 3 && tempo == 0) + { + tempo = millis(); } - - if (abs(p0 - v0) < 3) { - m0 = m1 = 0; - - } else { - - if (p0 < v0) - { - m0 = 1; - m1 = 0; - } - - if (p0 > v0) - { - m0 = 0; - m1 = 1; - } + if (etape == 3 && millis() > tempo + 3000) + { + etape = 4; + tempo = 0; } - // Prêt pour un nouveau tour + if (etape == 4 && capteur[2] == 1) + { + etape = 5; + } + + if (etape == 5 && capteur[5] == 1) + { + etape = 6; + } + + if (etape == 6 && c7_frontdescendant == 1) + { + etape = 1; + } + + sortie[10] = etape; + sortie[11] = ci; + + actionneur[0] = (etape == 1); + actionneur[1] = (etape == 2 || etape == 3); + actionneur[2] = (etape == 5); + actionneur[3] = (etape == 6); + + // Prêt pour un nouveau cycle // L'état courant devient l'état précédent + marche_precedent = marche; + arret_precedent = arret; for (int i = 0; i < 8; i++) { bouton_precedent[i] = bouton[i]; } - marche_precedent = marche; - arret_precedent = arret; + c7_precedent = capteur[7]; }