//------------------------------------------------------
// 3-colour LED: XJEase device file
// 3-colour-LED.xje Revision: 1.12
// (c)2002-2007 XJTAG Limited
//
// Disclaimer: XJTAG makes no guarantees whatsoever
// about this code.  You use it at your own risk ...
// This code requires XJTAG version 1.3.1 or later.
//------------------------------------------------------

DEVICE NAME := "3 colour LED"

  PINS
    RED_LED   := 3;
    GREEN_LED := 2;
  END;

  TEST COVERAGE
    RED_LED   := OPEN HI LO;
    GREEN_LED := OPEN HI LO;
  END;

END;

//------------------------------------------------------
// LED colours constants
//------------------------------------------------------
CONST INT OFF := 0;
CONST INT RED := 1;
CONST INT GREEN := 2;
CONST INT ORANGE := 3;


//------------------------------------------------------
SetLED(INT value)()
//------------------------------------------------------
  SET RED_LED := value[0], GREEN_LED := value[1];
END;

//------------------------------------------------------
Test()(INT result)
//------------------------------------------------------
  INT key;
  
  PRINT("Is LED ", DEVICE_REF, " toggling red and green?\nPress the Spacebar to pass or any other key to fail.\n");
  ALERT();
  
  DO 
    SetLED(RED)();
    SLEEP(100);
    SetLED(GREEN)();
    SLEEP(100);
    key := GETKEY();
  WHILE key = 0
  END;
  
  IF key = ASC(" ") THEN
    result := RESULT_PASS;
  ELSE
    result := RESULT_FAIL;
  END;
  
  //Make sure both the LEDs are switched off at the end.
  SetLED(OFF)();
END;