Sketch work
This commit is contained in:
parent
dbcf6c1b6e
commit
31d1a6dbba
|
@ -1,10 +1,11 @@
|
|||
|
||||
/**
|
||||
* Prototype
|
||||
* Arduino Uno
|
||||
* Arduino Nano
|
||||
* L298N
|
||||
**/
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define Fpos 9
|
||||
#define Fneg 10
|
||||
|
||||
|
@ -17,6 +18,10 @@
|
|||
#define Fbutton 3
|
||||
#define Bbutton 4
|
||||
|
||||
const int Buttons[2] = {Fbutton, Bbutton};
|
||||
volatile int ButtonState[4] = {1, 1};
|
||||
volatile long ButtonTime[4] = {0, 0};
|
||||
|
||||
const int Fmotor = 0;
|
||||
const int Bmotor = 1;
|
||||
|
||||
|
@ -26,9 +31,15 @@ volatile int Bspeed = 255;
|
|||
volatile boolean Frunning = false;
|
||||
volatile boolean Brunning = false;
|
||||
|
||||
volatile char cmdChar = 'z';
|
||||
const char Fcmd = 'D';
|
||||
const char Bcmd = 'E';
|
||||
|
||||
SoftwareSerial softSerial (Fsignal, Bsignal);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(57600);
|
||||
Serial.println("Started takeup demo");
|
||||
softSerialmy.begin(9600);
|
||||
pinMode(Fpos, OUTPUT);
|
||||
pinMode(Fneg, OUTPUT);
|
||||
pinMode(Bpos, OUTPUT);
|
||||
|
@ -39,6 +50,24 @@ void setup() {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available()) {
|
||||
cmdChar = (char)Serial.read();
|
||||
}
|
||||
if (cmdChar != 'z') {
|
||||
cmd(cmdChar);
|
||||
}
|
||||
|
||||
if (softSerial.available() > 0) {
|
||||
cmdChar = (char)softSerial.read();
|
||||
}
|
||||
if (cmdChar != 'z') {
|
||||
cmd(cmdChar);
|
||||
}
|
||||
|
||||
cmdChar = 'z';
|
||||
}
|
||||
|
||||
void cmd (char which) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -152,6 +181,44 @@ void brakeMotor (int motor) {
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------
|
||||
* Reads the state of a specific button and compares
|
||||
* it to a stored value in the button_state array.
|
||||
* If the value is different than what is stored,
|
||||
* check if button is pressed and store new timer value,
|
||||
* if button is released, compare current time to the stored
|
||||
* time value and pass that to the button_end function.
|
||||
* ------------------------------------------------*/
|
||||
void btn (int index) {
|
||||
int val = digitalRead(Buttons[index]);
|
||||
if (val != ButtonState[index]) {
|
||||
if (val == LOW) { // pressed
|
||||
ButtonTime[index] = millis();
|
||||
} else if (val == HIGH) { // not pressed
|
||||
buttontime = millis() - ButtonTime[index];
|
||||
button_end(index, buttontime);
|
||||
}
|
||||
}
|
||||
ButtonState[index] = val;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------
|
||||
* Determines a specific action for each press length
|
||||
* of each button.
|
||||
* ------------------------------------------------*/
|
||||
void button_end (int index, long buttontime) {
|
||||
if (index == 0) { //forward
|
||||
if (buttontime > 10) {
|
||||
//
|
||||
}
|
||||
} else if (index == 1) { //backward
|
||||
if (buttontime > 10) {
|
||||
//
|
||||
}
|
||||
}
|
||||
buttontime = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
Loading…
Reference in New Issue