Hi guys,
I am hoping you can help with this very odd problem. I'm using a Mega as part of an Industrial Shields MDuino 21+ controller (Product Link).
I am trying to control one of the PWM output pins, which works fine until I add a certain line of code, and then previous code stops working! I am at a total loss here.. but also fairly new to Arduino programming.
Here is the code: (please note, for the MDuino you do not need to setup pins with output types etc.)
void setup() {
// put your setup code here, to run once:
}
void loop() {
//Motor 1 - Run FWD, full speed
digitalWrite(Q0_2, LOW);
digitalWrite(Q0_1, HIGH);
analogWrite(Q0_7, 255);
delay(3000);
//Motor 1 - Run REV, full speed
digitalWrite(Q0_1, LOW);
digitalWrite(Q0_2, HIGH);
analogWrite(Q0_7, 255); //change to 255
delay(3000);
//Motor 1 - Run FWD, low speed
digitalWrite(Q0_2, LOW);
digitalWrite(Q0_1, HIGH);
analogWrite(Q0_7, 60);
delay(3000);
//Motor 1 - Run REV, low speed
digitalWrite(Q0_1, LOW);
digitalWrite(Q0_2, HIGH);
// analogWrite(Q0_7, 60); //this line breaks the code...?
delay(3000);
}
The PWM outputs as it should as long as the commented 'analogWrite(Q0_7, 60);' line stays commented, but as soon as I uncomment it, the previous 'analogWrite(Q0_7, 60);' and the now uncommented line do not work.
How can later code be affecting what is happening earlier, and why on earth would this happen?
many thanks