// Test
// Can the information be put in data instead of code ?
// This Wokwi project: https://wokwi.com/projects/412490259558899713
//
// Original by Sailor Mike: https://wokwi.com/projects/412465895466991617
//
int onOff = 1500;
#define NUM_WIRES 3
// Pin 10 is blue wire, pin 11 orange wire, pin 12 green wire.
int outputs[NUM_WIRES] = {10, 11, 12};
// Array that defines what the outputs do.
// There is logic in the order of the data,
// but it is not binary order, so I had to
// make the full definition in the array.
int led[6][NUM_WIRES][2] =
{
{ {INPUT,LOW},{OUTPUT,HIGH},{OUTPUT,LOW} }, // white led
{ {INPUT,LOW},{OUTPUT,LOW},{OUTPUT,HIGH} }, // cyan led
{ {OUTPUT,HIGH},{INPUT,LOW},{OUTPUT,LOW} }, // red led
{ {OUTPUT,LOW},{INPUT,LOW},{OUTPUT,HIGH} }, // blue led
{ {OUTPUT,HIGH},{OUTPUT,LOW},{INPUT,LOW} }, // green led
{ {OUTPUT,LOW},{OUTPUT,HIGH},{INPUT,LOW} }, // yellow led
};
// anonymus enum, that's not good, is it ?
enum
{
WHITE,
CYAN,
RED,
BLUE,
GREEN,
YELLOW
};
void setup()
{
//Serial.begin(115200);
}
void loop()
{
lights(WHITE);
delay(onOff);
lights(CYAN);
delay(onOff);
lights(RED);
delay(onOff);
lights(BLUE);
delay(onOff);
lights(GREEN);
delay(onOff);
lights(YELLOW);
delay(onOff);
}
void lights(int light)
{
// Turn them off first, to avoid glitches
for(int i=0; i<NUM_WIRES; i++)
{
pinMode(outputs[i], INPUT);
}
// Use the array with the definitions.
for(int i=0; i<NUM_WIRES; i++)
{
pinMode(outputs[i], led[light][i][0]);
digitalWrite(outputs[i], led[light][i][1]);
}
}