Sketch is the same as your except I deleted the DEFAULT case and it worked.
I haven't yet reviewed your sketch to fully understand your inputs and bins etc.
Attached is the wiring diagram and the your sketch minus the DEFAULT case which works.
Ideally, what this project is to do is for the arduino to be on with cyan LED. When amplifier is on, it supplies 12v signal in to pin 9. Arduino sees this, and activates the linear actuator to open the centre speaker door making the LED green whilst doing so. Once the door is open, the amp is on, so the arduino LED will be magenta. If amp turns off, arduino will close door making LED red whilst doing so, then return to cyan colour to show arduino power on but amp off. Rocker switch is for manual open/close of door hence neutral position, position 1 open/green and position 2 closed/red.
I have built the cabinet, designed and 3d printed the clevisis for the actuator which allow adjustment of door closed position, and it works perfectly, Now just to have it working automatically on amplifier switching...... Oh and I am using an Uno instead of a Nano as couldn't get nano working.....for now
// Prior to Setup
int green_light_pin = 5; ;// Green pin connected to digital pin 5
int blue_light_pin = 6; // Blue pin connected to digital pin 6
int red_light_pin = 7; // Red pin connected to digital pin 7
int switch_on_pin = 11; // switch on pin connected to digital pin 11
int switch_off_pin = 10; // switch off pin connected to digital pin 10
int switch_on_val = 0; // value used to store the state of the input pin
int switch_off_val = 0; // value used to store the state of the input pin
int switchon_valbin = 0; // value used to store the state of the input pin
int switchoff_valbin = 0; // value used to store the state of the input pin
int LEDVal = 0;
// Setup
void setup() {
pinMode(green_light_pin, OUTPUT); // sets the greenPin as an output
pinMode(blue_light_pin, OUTPUT); // sets the bluePin as an output
pinMode(red_light_pin, OUTPUT); // sets the redPin as an output
pinMode(switch_on_pin, INPUT_PULLUP); // declare on switch as input + activate internal pull-up resistor
pinMode(switch_off_pin, INPUT_PULLUP); // declare off switch as input + activate internal pull-up resistor
// turn LED cyan
RGB_color(0, 255, 255);
// initialize serial communication:
Serial.begin(9600);
} // close void setup
// Loop
void loop() {
switch_on_val = digitalRead(switch_on_pin); // read the state
if (switch_on_val) // Assign a value to switch position
{
switchon_valbin = 1;
}
else
{
switchon_valbin = 0;
}
switch_off_val = digitalRead(switch_off_pin); // read the state
if (switch_off_val) // Assign a value to switch position
{
switchoff_valbin = 2;
}
else
{
switchoff_valbin = 0;
}
LEDVal = switchon_valbin + switchoff_valbin; // Calculate the LED display Value
switch (LEDVal) // Select the RGB colour according to switch value
{
case 1: // Red
RGB_color(255, 0, 0);
Serial.println("Switch in RED position");
break;
case 2: // Green
RGB_color(0, 255, 0);
Serial.println("Switch in GREEN position");
break;
case 3: // Blue
RGB_color(0, 0, 255);
Serial.println("Switch in CENTRE BLUE position");
default: //had to delete this DEFAULT section to make it work properly SF
RGB_color(0, 0, 0);
Serial.println("Switch in UNDEFINED position");
break;
}
delay(250); // delay to slow the monitor update down
}
// this following void command is like a DEFINE FUNCTION command in that it defines rgb color as a command consisting of 3 integers and then as specified in the curly brackets, analogwrites to each of these as specified
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
analogWrite(blue_light_pin, blue_light_value);
}
void switch_on() //switch on subroutine function
{
RGB_color(0, 255, 0); // turn green
Serial.println("LED is green for switch on ");
}
void switch_off() //switch off subroutine function
{
RGB_color(255, 0, 0); // turn red
Serial.println("LED is red for switch on ");
}