From 7400dc68a9ec4c5ef9c588adfee52931fc479001 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Fri, 10 Feb 2023 15:36:17 -0500 Subject: [PATCH] Start button logic --- ino/demo/demo.ino | 4 ++-- ino/takeup/takeup.ino | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/ino/demo/demo.ino b/ino/demo/demo.ino index 3153ca5..974fada 100644 --- a/ino/demo/demo.ino +++ b/ino/demo/demo.ino @@ -142,9 +142,9 @@ void brake (){ } /** - * Vex = higher voltage that can power the motor and/or the shield as well as the Arduino if wanted + * Vex = Higher voltage that can power the motor and/or the shield as well as the Arduino if wanted * 5V = Must be a clean 5V that can power the Arduino and shield, and if wanted also the motor itself - * GND = ass always, the ground of everything + * GND = Ass always, the ground of everything * B- = Connection of the first motor or first winding of the stepper motor * B+ = Connection of the first motor or first winding of the stepper motor * A- = Connection of the second motor or second winding of the stepper motor diff --git a/ino/takeup/takeup.ino b/ino/takeup/takeup.ino index 6fdf775..ca1e15a 100644 --- a/ino/takeup/takeup.ino +++ b/ino/takeup/takeup.ino @@ -6,6 +6,10 @@ #include +/** + * CONSTANTS + **/ + #define Fpos 9 #define Fneg 10 @@ -18,6 +22,13 @@ #define Fbutton 3 #define Bbutton 4 +const frameTime = 40; //ms +const frameSpeed = 255; + +/** + * STATE + **/ + const int Buttons[2] = {Fbutton, Bbutton}; volatile int ButtonState[4] = {1, 1}; volatile long ButtonTime[4] = {0, 0}; @@ -32,15 +43,28 @@ volatile int Bspeed = 255; volatile boolean Frunning = false; volatile boolean Brunning = false; +voilatile long timer = 0; + +/** + * SERIAL + **/ + volatile char cmdChar = 'z'; const char Fcmd = 'D'; const char Bcmd = 'E'; +const int serialDelay = 5; + SoftwareSerial softSerial (Fsignal, Bsignal); void setup() { Serial.begin(57600); + Serial.flush(); + Serial.setTimeout(serialDelay); + softSerial.begin(9600); + softSerial.flush(); + softSerial.setTimeout(serialDelay); pinMode(Fpos, OUTPUT); pinMode(Fneg, OUTPUT); @@ -196,10 +220,14 @@ void btn (int index) { if (val != ButtonState[index]) { if (val == LOW) { // pressed ButtonTime[index] = millis(); + button_start(index, buttontime); } else if (val == HIGH) { // not pressed buttontime = millis() - ButtonTime[index]; button_end(index, buttontime); } + } + if (val == LOW) { + } ButtonState[index] = val; } @@ -222,9 +250,9 @@ void button_end (int index, long buttontime) { } /** - * Vex = higher voltage that can power the motor and/or the shield as well as the Arduino if wanted + * Vex = Higher voltage that can power the motor and/or the shield as well as the Arduino if wanted * 5V = Must be a clean 5V that can power the Arduino and shield, and if wanted also the motor itself - * GND = ass always, the ground of everything + * GND = as always, the ground of everything * B- = Connection of the first motor or first winding of the stepper motor * B+ = Connection of the first motor or first winding of the stepper motor * A- = Connection of the second motor or second winding of the stepper motor