/*
 * Board:   Arduino Uno
 * Target:  PE Series on LED Effects
 * Author:  Clive "Max" Maxfield (max@clivemaxfield.com) 
 * License: The MIT License (See full license at the bottom of this file)
 *
 * Notes:   Switch -> On;  GLED -> On;  RLED -> Off
 *          Switch -> Off; GLED -> Off; RLED -> On
 */

#define SWITCH_ON      LOW
#define SWITCH_OFF    HIGH

#define LED_ON        HIGH
#define LED_OFF        LOW

int PinSwitch   =  4;
int PinGreenLed =  9;
int PinRedLed   = 10;

int OldSwitchState;
int NewSwitchState;


void setup ()
{
    pinMode(PinSwitch,   INPUT);
    pinMode(PinGreenLed, OUTPUT);
    pinMode(PinRedLed,   OUTPUT);
    
    OldSwitchState = digitalRead(PinSwitch);

    if (OldSwitchState == SWITCH_ON)
    {
        digitalWrite(PinGreenLed, LED_ON);
        digitalWrite(PinRedLed,   LED_OFF);
    }
    else
    {
        digitalWrite(PinGreenLed, LED_OFF);
        digitalWrite(PinRedLed,   LED_ON);
    }
}


void loop ()
{
    NewSwitchState = digitalRead(PinSwitch);

    if (NewSwitchState != OldSwitchState)
    {
        if (NewSwitchState == SWITCH_ON)
        {
            digitalWrite(PinGreenLed, LED_ON);
            digitalWrite(PinRedLed,   LED_OFF);
        }
        else
        {
            digitalWrite(PinGreenLed, LED_OFF);
            digitalWrite(PinRedLed,   LED_ON);
        }

        OldSwitchState = NewSwitchState;
    }
}


/*
 * Copyright (c) 2020 Clive "Max" Maxfield
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and any associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */