// Galaya simulation
// Initializations
int mode = 0;
int cptOrder = 0;
int cptManifacturing = 0;
int orderArray[1000] = {};
void setup() {
// put your setup code here, to run once:
// outputs
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
// inputs
attachInterrupt(digitalPinToInterrupt(18), yellow, RISING);
attachInterrupt(digitalPinToInterrupt(19), blue, RISING);
attachInterrupt(digitalPinToInterrupt(20), green, RISING);
attachInterrupt(digitalPinToInterrupt(21), red, RISING);
}
void loop() {
// put your main code here, to run repeatedly:
// State machine
switch (mode) {
case 0:
if (cptOrder>cptManifacturing) { // Do nothing if nothing was called
cptManifacturing++;
mode = orderArray[cptManifacturing];
}
break;
case 1:
doRoutine(8);
mode = 0;
break;
case 2:
doRoutine(9);
mode = 0;
break;
case 3:
doRoutine(10);
mode = 0;
break;
case 4:
doRoutine(11);
mode = 0;
break;
}
}
void doRoutine(int i) {
digitalWrite(i, HIGH);
delay(2000);
digitalWrite(i, LOW);
delay(500);
}
// Interrupt ISR
void yellow() {
cptOrder++;
orderArray[cptOrder] = 1;
}
void blue() {
cptOrder++;
orderArray[cptOrder] = 2;
}
void green() {
cptOrder++;
orderArray[cptOrder] = 3;
}
void red() {
cptOrder++;
orderArray[cptOrder] = 4;
}