Exemplo n.º 1
0
/* This example turns all 4 leds on and then off */
int main(void) {

    // Access 4 leds predefined as LED1, LED2, LED3, LED4
    Pin_t leds[] = {
        Pin_Init(LED1, 1, Output),
        Pin_Init(LED2, 1, Output),
        Pin_Init(LED3, 1, Output),
    };
    int nleds = 3;

    Pin_t button = Pin_Init(SW1, 1, Output);
    Pin_Input(button),
    Pin_Mode(button, PullUp);

    // Get the sensor enabler
    Pin_t enabler = Pin_Init(LED_EN, 1, Output);
    Pin_Output(enabler),
    Pin_On(enabler);

    // Get AnalogIns
    uint32_t sensors[] = {
        AnalogIn_Get(SENS0),
        AnalogIn_Get(SENS1),
        AnalogIn_Get(SENS2),
        AnalogIn_Get(SENS3),
        AnalogIn_Get(SENS4) };
    int nsensors = 5;

    while (1) {
        if (Pin_Read(button) == SW_ON) {
            Pin_Off(leds[2]);
        } else {
            Pin_On(leds[2]);
        }
        if (AnalogIn_Read(sensors[0]) > 0) {
            Pin_Off(leds[1]);
        } else {
            Pin_On(leds[1]);
        }


/*      for (i = 0; i < nleds; i++) {
            Pin_On(leds[i]);
            Delay(0.2);
        }
        for (i = 0; i < nleds; i++) {
            Pin_Off(leds[i]);
            Delay(0.2);
        }*/
    }
}
Exemplo n.º 2
0
AnalogIn_t AnalogIn_Init(PinName pin_name) {

    // Check if the global initialization is needed.
    if (!(PMC->PMC_PCER0 & ADC_POWER_BITMASK)) {
        ADC_Init();
    }

    AnalogIn_t analog_in = AnalogIn_Get(pin_name);

    // Set the pin bit function
    Pin_t pin = Pin_Get(pin_name);
    Pin_Input(pin);
    Pin_Mode(pin, PullNone);
    Pin_Mode(pin, PD);

    return analog_in;
}