add led function
This commit is contained in:
parent
fd3a474f18
commit
fea152adc8
|
@ -76,6 +76,10 @@ float filtered_currentAll=0;
|
||||||
int16_t cmd_send=0;
|
int16_t cmd_send=0;
|
||||||
int16_t last_cmd_send=0;
|
int16_t last_cmd_send=0;
|
||||||
|
|
||||||
|
uint8_t speedmode=0;
|
||||||
|
#define SPEEDMODE_SLOW 1
|
||||||
|
#define SPEEDMODE_NORMAL 0
|
||||||
|
|
||||||
|
|
||||||
// Global variables for serial communication
|
// Global variables for serial communication
|
||||||
typedef struct{
|
typedef struct{
|
||||||
|
@ -149,6 +153,7 @@ void failChecks();
|
||||||
void sendCMD();
|
void sendCMD();
|
||||||
void checkLog();
|
void checkLog();
|
||||||
void updateMotorparams( MotorParameter &mp, SerialFeedback &fb);
|
void updateMotorparams( MotorParameter &mp, SerialFeedback &fb);
|
||||||
|
void leds();
|
||||||
|
|
||||||
void SendSerial(SerialCommand &scom, int16_t uSpeedLeft, int16_t uSpeedRight, HardwareSerial &SerialRef)
|
void SendSerial(SerialCommand &scom, int16_t uSpeedLeft, int16_t uSpeedRight, HardwareSerial &SerialRef)
|
||||||
{
|
{
|
||||||
|
@ -243,7 +248,7 @@ void setup()
|
||||||
pinMode(PIN_START, INPUT_PULLUP);
|
pinMode(PIN_START, INPUT_PULLUP);
|
||||||
|
|
||||||
pinMode(PIN_LED_START, OUTPUT); //Active High
|
pinMode(PIN_LED_START, OUTPUT); //Active High
|
||||||
digitalWrite(PIN_LED_START,HIGH);
|
|
||||||
pinMode(PIN_MODE_LEDG, OUTPUT); //Active Low
|
pinMode(PIN_MODE_LEDG, OUTPUT); //Active Low
|
||||||
digitalWrite(PIN_MODE_LEDG,LOW);
|
digitalWrite(PIN_MODE_LEDG,LOW);
|
||||||
pinMode(PIN_MODE_LEDR, OUTPUT); //Active Low
|
pinMode(PIN_MODE_LEDR, OUTPUT); //Active Low
|
||||||
|
@ -287,6 +292,8 @@ void loop() {
|
||||||
//If needed write log to serial port
|
//If needed write log to serial port
|
||||||
checkLog();
|
checkLog();
|
||||||
|
|
||||||
|
leds();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -378,14 +385,19 @@ void readADC() {
|
||||||
//Serial.print(throttle_raw); Serial.print(", "); Serial.print(brake_raw); Serial.print(", ");
|
//Serial.print(throttle_raw); Serial.print(", "); Serial.print(brake_raw); Serial.print(", ");
|
||||||
//Serial.print(throttle_pos); Serial.print(", "); Serial.print(brake_pos); Serial.println();
|
//Serial.print(throttle_pos); Serial.print(", "); Serial.print(brake_pos); Serial.println();
|
||||||
|
|
||||||
|
|
||||||
if (digitalRead(PIN_MODE_SWITCH)) { //pushed in, also high if cable got disconnected
|
if (digitalRead(PIN_MODE_SWITCH)) { //pushed in, also high if cable got disconnected
|
||||||
throttle_pos/=2;
|
speedmode=SPEEDMODE_SLOW;
|
||||||
digitalWrite(PIN_MODE_LEDG,LOW); //Green, low is on
|
|
||||||
digitalWrite(PIN_MODE_LEDR,HIGH);
|
|
||||||
}else{ //button not pushed in
|
}else{ //button not pushed in
|
||||||
digitalWrite(PIN_MODE_LEDG,HIGH);
|
speedmode=SPEEDMODE_NORMAL;
|
||||||
digitalWrite(PIN_MODE_LEDR,LOW); //Red
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (speedmode==SPEEDMODE_SLOW) {
|
||||||
|
throttle_pos/=2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void failChecks() {
|
void failChecks() {
|
||||||
|
@ -509,3 +521,15 @@ void updateMotorparams( MotorParameter &mp, SerialFeedback &fb) {
|
||||||
mp.millis=loopmillis;
|
mp.millis=loopmillis;
|
||||||
log_update=true;
|
log_update=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void leds() {
|
||||||
|
digitalWrite(PIN_LED_START,(loopmillis/1000)%2 == 0); //high is on for LED_START
|
||||||
|
|
||||||
|
if (speedmode==SPEEDMODE_SLOW) {
|
||||||
|
digitalWrite(PIN_MODE_LEDG,LOW); //Green, low is on
|
||||||
|
digitalWrite(PIN_MODE_LEDR,HIGH);
|
||||||
|
}else if (speedmode==SPEEDMODE_NORMAL) {
|
||||||
|
digitalWrite(PIN_MODE_LEDG,HIGH);
|
||||||
|
digitalWrite(PIN_MODE_LEDR,LOW); //Red
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue