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;
}
Exemplo n.º 4
0
/**
 * Routine to initialize all of the LEDs
 * 
 * Note: This procedure *does* enable the appropriate port clock
 */
void ledInitAll(void) {
	/* Enable the clock for PORTA using the SIM_SCGC5 register (System Clock Gating
	 * Control Register 5) (See 12.2.13 on page 342 of the K70 Sub-Family Reference
	 * Manual, Rev. 2, Dec 2011) */
	SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;
	
	/* Turn off the LEDs */
	ledOrangeOff();
	ledYellowOff();
	ledGreenOff();
	ledBlueOff();

	/* Configure the LED ports */
	ledOrangeConfig();
	ledYellowConfig();
	ledGreenConfig();
	ledBlueConfig();
}