Start button logic
This commit is contained in:
parent
45fc1abd77
commit
7400dc68a9
|
@ -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
|
* 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
|
||||||
* 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
|
* A- = Connection of the second motor or second winding of the stepper motor
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CONSTANTS
|
||||||
|
**/
|
||||||
|
|
||||||
#define Fpos 9
|
#define Fpos 9
|
||||||
#define Fneg 10
|
#define Fneg 10
|
||||||
|
|
||||||
|
@ -18,6 +22,13 @@
|
||||||
#define Fbutton 3
|
#define Fbutton 3
|
||||||
#define Bbutton 4
|
#define Bbutton 4
|
||||||
|
|
||||||
|
const frameTime = 40; //ms
|
||||||
|
const frameSpeed = 255;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* STATE
|
||||||
|
**/
|
||||||
|
|
||||||
const int Buttons[2] = {Fbutton, Bbutton};
|
const int Buttons[2] = {Fbutton, Bbutton};
|
||||||
volatile int ButtonState[4] = {1, 1};
|
volatile int ButtonState[4] = {1, 1};
|
||||||
volatile long ButtonTime[4] = {0, 0};
|
volatile long ButtonTime[4] = {0, 0};
|
||||||
|
@ -32,15 +43,28 @@ volatile int Bspeed = 255;
|
||||||
volatile boolean Frunning = false;
|
volatile boolean Frunning = false;
|
||||||
volatile boolean Brunning = false;
|
volatile boolean Brunning = false;
|
||||||
|
|
||||||
|
voilatile long timer = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SERIAL
|
||||||
|
**/
|
||||||
|
|
||||||
volatile char cmdChar = 'z';
|
volatile char cmdChar = 'z';
|
||||||
const char Fcmd = 'D';
|
const char Fcmd = 'D';
|
||||||
const char Bcmd = 'E';
|
const char Bcmd = 'E';
|
||||||
|
|
||||||
|
const int serialDelay = 5;
|
||||||
|
|
||||||
SoftwareSerial softSerial (Fsignal, Bsignal);
|
SoftwareSerial softSerial (Fsignal, Bsignal);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(57600);
|
Serial.begin(57600);
|
||||||
|
Serial.flush();
|
||||||
|
Serial.setTimeout(serialDelay);
|
||||||
|
|
||||||
softSerial.begin(9600);
|
softSerial.begin(9600);
|
||||||
|
softSerial.flush();
|
||||||
|
softSerial.setTimeout(serialDelay);
|
||||||
|
|
||||||
pinMode(Fpos, OUTPUT);
|
pinMode(Fpos, OUTPUT);
|
||||||
pinMode(Fneg, OUTPUT);
|
pinMode(Fneg, OUTPUT);
|
||||||
|
@ -196,10 +220,14 @@ void btn (int index) {
|
||||||
if (val != ButtonState[index]) {
|
if (val != ButtonState[index]) {
|
||||||
if (val == LOW) { // pressed
|
if (val == LOW) { // pressed
|
||||||
ButtonTime[index] = millis();
|
ButtonTime[index] = millis();
|
||||||
|
button_start(index, buttontime);
|
||||||
} else if (val == HIGH) { // not pressed
|
} else if (val == HIGH) { // not pressed
|
||||||
buttontime = millis() - ButtonTime[index];
|
buttontime = millis() - ButtonTime[index];
|
||||||
button_end(index, buttontime);
|
button_end(index, buttontime);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (val == LOW) {
|
||||||
|
|
||||||
}
|
}
|
||||||
ButtonState[index] = val;
|
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
|
* 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
|
||||||
* 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
|
* A- = Connection of the second motor or second winding of the stepper motor
|
||||||
|
|
Loading…
Reference in New Issue