Hi all,
I am wondering if it's my code or my hardware here.
If I run the code below only every second digital output works.
I have confirmed on my oscilloscope that the pins are defiantly not toggling.
The pins that are not working are marked in the commented code.
Can you blow up a mega so that only every second digital output works and the others fail ?
class Step
{
public:
byte A;
byte B;
byte D;
byte previousState;
int stepDelay;
bool CW;
unsigned long previousMillis;
public:
Step(byte pin1, byte pin2, byte pin3, bool Dir, int sDelay)
{
A = pin1;
B = pin2;
D = pin3;
stepDelay = sDelay;
CW = Dir;
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(D, INPUT);
}
void updateStep(bool CW, int stepDelay)
{
int atD = 0;
atD = digitalRead(D);
if (atD)
{
digitalWrite(LED_BUILTIN, HIGH);
}
else digitalWrite(LED_BUILTIN, LOW);
if ((millis() - previousMillis >= stepDelay))
{
switch (previousState) {
case 0:
previousState = 1;
digitalWrite(A, LOW);
digitalWrite(B, LOW);
previousMillis = millis();
break;
case 1:
previousState = 2;
if (CW == true)
{
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
}
else
{
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
}
previousMillis = millis();
break;
case 2:
previousState = 0;
if (CW == true)
{
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
}
else
{
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
}
previousMillis = millis();
break;
} // end of switch case
}
}
};
Step DM1(22, 23, 24, true, 0);
Step DM2(25, 26, 27, true, 0); //error not moving.
Step DM3(28, 29, 30, true, 0);
Step DM4(31, 32, 33, true, 0); //error not moving.
Step DM5(34, 35, 36, true, 0);
Step DM6(37, 38, 39, true, 0); //error not moving
Step DM7(40, 41, 42, true, 0);
Step DM8(43, 44, 45, true, 0); //error not moving.
Step DM9(46, 47, 48, true, 0);
Step DM10(0, 1, 2, true, 0); //error not moving
Step DM11(4, 3, 5, true, 0);
Step DM12(7, 6, 8, true, 0); //error not moving
Step DM13(10, 9, 11, true, 0);
void setup()
{
}
void loop() {
DM1.updateStep(true, 10);
DM2.updateStep(true, 10);
DM3.updateStep(true, 10);
DM4.updateStep(true, 10);
DM5.updateStep(true, 10);
DM6.updateStep(true, 10);
DM7.updateStep(true, 10);
DM8.updateStep(true, 10);
DM9.updateStep(true, 10);
DM10.updateStep(true, 10);
DM11.updateStep(true, 10);
DM12.updateStep(true, 10);
DM13.updateStep(true, 10);
}