working leds in digital mode. pwm did not work correctly
This commit is contained in:
parent
1a0ab28c21
commit
4c153f28e8
|
@ -157,7 +157,7 @@ void setup()
|
|||
Serial2.begin(SERIAL_CONTROL_BAUD); //control. B10=TX3, B11=RX3 (Serial2 is Usart 3). Marked with "II" on connector (Front)
|
||||
|
||||
// Pin Setup
|
||||
pinMode(PIN_STARTLED, OUTPUT);
|
||||
pinMode(PIN_STARTLED, OUTPUT); //MODE=PWM (needs testing, mcu locks up when using writePWM()
|
||||
pinMode(PIN_ENABLE, OUTPUT);
|
||||
digitalWrite(PIN_ENABLE, HIGH); //keep power on
|
||||
pinMode(PIN_STARTBUTTON, INPUT_PULLUP);
|
||||
|
@ -282,7 +282,6 @@ void handleModeChange() {
|
|||
requestmode=idle; //start in idle state
|
||||
state_modechange=0; //reset state for safety
|
||||
}//TODO else if (button_hold_start) { requestmode=on; }
|
||||
//TODO: led show
|
||||
break;
|
||||
case idle:
|
||||
if (button_hold_start){ //long press
|
||||
|
@ -427,7 +426,6 @@ void modeloops() {
|
|||
last_looptime=loopmillis;
|
||||
switch (currentmode) { //mode changes
|
||||
case booting:
|
||||
//TODO: LED effect
|
||||
break;
|
||||
case idle:
|
||||
loop_idle();
|
||||
|
@ -461,14 +459,11 @@ void loop_on() {
|
|||
|
||||
void loop_error() {
|
||||
out_speedFL=out_speedFR=out_speedRR=out_speedRL=0; //stop motors
|
||||
Serial.print("Error:"); Serial.println(errormessage);
|
||||
//TODO: blink error led
|
||||
|
||||
Serial.print("Error:"); Serial.println(errormessage);
|
||||
}
|
||||
|
||||
void loop_off() {
|
||||
//loop enters when boards are sucessfully turned off
|
||||
//TODO: led show
|
||||
digitalWrite(PIN_ENABLE, LOW); //cut own power
|
||||
|
||||
}
|
||||
|
@ -552,16 +547,16 @@ String modeToString(uint8_t m) {
|
|||
}
|
||||
|
||||
|
||||
void ledUpdate () {
|
||||
void ledUpdate() {
|
||||
#define LEDUPDATETIME 20
|
||||
#define FASTERRORBLINKDELAY 200 //period for startled to blink on error
|
||||
#define FASTERRORBLINKDELAY 100 //period for startled to blink on error
|
||||
if (loopmillis - last_ledupdate >= LEDUPDATETIME) {
|
||||
last_ledupdate=loopmillis;
|
||||
// ## StartLed ##
|
||||
uint8_t _ledbrightness;
|
||||
switch (currentmode) { //modeLed for different currentmodes
|
||||
case booting: //Startled dimmed
|
||||
startled=127;
|
||||
startled=255;
|
||||
break;
|
||||
case idle: //Breathing Startled
|
||||
_ledbrightness=uint8_t( (loopmillis/10)%(512) );
|
||||
|
@ -584,7 +579,7 @@ void ledUpdate () {
|
|||
}else{
|
||||
switch (currentmode) { //modeLed for different currentmodes
|
||||
case booting:
|
||||
modeled_green=255; modeled_red=127; //ModeLed=Lime
|
||||
modeled_green=255; modeled_red=0; //ModeLed=Green
|
||||
break;
|
||||
case idle:
|
||||
modeled_green=255; modeled_red=255; //ModeLed=Yellow
|
||||
|
@ -596,13 +591,18 @@ void ledUpdate () {
|
|||
modeled_green=0; modeled_red=255; //ModeLed=Red
|
||||
break;
|
||||
case off:
|
||||
modeled_green=255; modeled_red=127; //ModeLed=Lime
|
||||
modeled_green=255; modeled_red=255; //ModeLed=Yellow
|
||||
break;
|
||||
}
|
||||
}
|
||||
analogWrite(PIN_MODELED_GREEN, map(modeled_green, 0, 255, 0, 65535));
|
||||
analogWrite(PIN_MODELED_RED, map(modeled_red, 0, 255, 0, 65535));
|
||||
analogWrite(PIN_STARTLED, map(startled, 0, 255, 0, 65535));
|
||||
/*
|
||||
pwmWrite(PIN_MODELED_GREEN, map(modeled_green, 0, 255, 0, 65535));
|
||||
pwmWrite(PIN_MODELED_RED, map(modeled_red, 0, 255, 0, 65535));
|
||||
pwmWrite(PIN_STARTLED, map(startled, 0, 255, 0, 65535));
|
||||
*/
|
||||
digitalWrite(PIN_MODELED_GREEN, modeled_green<127? true:false); //red and green inverted (common anode)
|
||||
digitalWrite(PIN_MODELED_RED, modeled_red<127? true:false); //red and green inverted (common anode)
|
||||
digitalWrite(PIN_STARTLED, startled>127? true:false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue