Exemplo n.º 1
0
/*
* Turns on one light and turns off remaing LEDs depending upon counter value
*/
void changestate(int counter)
{
	switch(counter)
	{
		case 0 ://orange on
			ledOrangeOn();
			ledYellowOff();
			ledGreenOff();
			ledBlueOff();
			break;
		case 1 ://yellow on
			ledOrangeOff();
			ledYellowOn();
			ledGreenOff();
			ledBlueOff();
			break;
		case 2 ://green on
			ledOrangeOff();
			ledYellowOff();
			ledGreenOn();
			ledBlueOff();
			break;
		case 3 ://blue on
			ledOrangeOff();
			ledYellowOff();
			ledGreenOff();
			ledBlueOn();
			break;
		default:
			break;
						
	}
}
Exemplo n.º 2
0
int main(void) {
    int number_presses = 0;

    /* Initialize all of the LEDs */
    ledInitAll();
    /* Initialize both of the pushbuttons */
    pushbuttonInitAll();

    /* initially orange LED should be on and all others should be off */
    ledOrangeOn();

    while(1) {
        if (sw1In()) {
            /* avoid contact bounce */
            delay(DELAY_LIMIT);

            number_presses++;
            if (number_presses == 4) {
                number_presses = 0;
            }

            if (number_presses == 0) {
                ledOrangeOn();
            } else {
                ledOrangeOff();
            }

            if (number_presses == 1) {
                ledYellowOn();
            } else {
                ledYellowOff();
            }

            if (number_presses == 2) {
                ledGreenOn();
            } else {
                ledGreenOff();
            }

            if (number_presses == 3) {
                ledBlueOn();
            } else {
                ledBlueOff();
            }

            /* wait until button released before checking if pushed again */
            while(sw1In()) { ; }
        }
    }

    return 0;
}
Exemplo n.º 3
0
/*
*   Implements write interface.
*   Parameters:
*       o void *fp - stream to read.
*       o char c - Expects 1 to turn on led and 0 to turn off.
*       Return : Number of bytes written
*/
int led_write(void *fp,char c)
{
	struct led_stream* stream = (struct led_stream*)fp;
	int val = c - '0';
	if(val)
	{
		switch(stream->minor)
		{
			case ORANGE:
				ledOrangeOn();				
				break;
			case YELLOW:
				ledYellowOn();				
				break;
			case GREEN:
				ledGreenOn();				
				break;
			case BLUE:
				ledBlueOn();				
				break;
			default:
				return 0;
		}
	}
	else
	{
		switch(stream->minor)
		{
			case ORANGE:
				ledOrangeOff();				
				break;
			case YELLOW:
				ledYellowOff();				
				break;
			case GREEN:
				ledGreenOff();				
				break;
			case BLUE:
				ledBlueOff();				
				break;
			default:
				return 0;
		}
	}
	return 1;
}