Hi,
I'm working to understand how you can set a pin on a 3D-Printer with the "M42" Code. Plattform is an Arduino Mega2560. Why would you use
digitalWrite(pin_number, com->S);
analogWrite(pin_number, com->S);
directly after each other on the same PIN "com->S"? Doesn't the "analogWrite" just overrides the previous "digitalWrite" command?
Here's the full code in "Commands.cpp":
void Commands::processMCode(GCode *com) {
switch( com->M ) [...]
case 42: //M42 -Change pin status via gcode
if (com->hasP()) {
int pin_number = com->P;
for(uint8_t i = 0; i < (uint8_t)sizeof(sensitive_pins); i++) {
if (pgm_read_byte(&sensitive_pins[i]) == pin_number) {
pin_number = -1;
break;
}
}
if (pin_number > -1) {
if(com->hasS()) {
if(com->S >= 0 && com->S <= 255) {
pinMode(pin_number, OUTPUT);
//-----------------------------------------------------------------------
digitalWrite(pin_number, com->S);
analogWrite(pin_number, com->S);
//-----------------------------------------------------------------------
Com::printF(Com::tSetOutputSpace, pin_number);
Com::printFLN(Com::tSpaceToSpace,(int)com->S);
} else
Com::printErrorFLN(PSTR("Illegal S value for M42"));
} else {
pinMode(pin_number, INPUT_PULLUP);
Com::printF(Com::tSpaceToSpace, pin_number);
Com::printFLN(Com::tSpaceIsSpace, digitalRead(pin_number));
}
} else {
Com::printErrorFLN(PSTR("Pin can not be set by M42, is in sensitive pins! "));
}
}
break;
}