ARM M4 Digital Input

Photo of author

By Jackson Taylor

1) Blink on Green led once when switch S1 press in launchpad

void setup()
{
    pinMode(PF_3, OUTPUT);   // setting PF.3 Pin as output
    digitalWrite(PF_3, HIGH); // turn the GREEN LED on
    delay(1000);               // wait for a second
    digitalWrite(PF_3, LOW);   // turn the GREEN LED off by making the voltage LOW
    delay(1000);
    pinMode(PF_4, INPUT_PULLUP);
}
void loop() {
    if(!digitalRead(PF_4)) //checking for logic zero
    {
        digitalWrite(PF_3, HIGH);   // turn the GREEN LED on
        delay(1000);               // wait for a second
        digitalWrite(PF_3, LOW);   // turn the GREEN LED off by making the voltage LOW
        delay(1000);               // wait for a second
    }
}

2) Blink on Blue led once when switch S2 press in launchpad

void setup()
{
    pinMode(PF_2, OUTPUT);   // setting PF.2 Pin as output
    pinMode(PF_0, INPUT_PULLUP); // setting PF.0 Pin as input with pull up
}
void loop() {
    if(!digitalRead(PF_0)) //checking for logic zero
    {
        digitalWrite(PF_2, HIGH);   // turn the GREEN LED on
        delay(1000);               // wait for a second
        digitalWrite(PF_2, LOW);   // turn the GREEN LED off by making the voltage LOW
        delay(1000);               // wait for a second
    }
}

3) Blinks Blue led once when switch S1 presses and Blinks Green led once when switch S2 presses on the launchpad

void setup()
{
    pinMode(PF_2, OUTPUT);   // setting PF.2 Pin as output
    pinMode(PF_3, OUTPUT);   // setting PF.3 Pin as output
    pinMode(PF_0, INPUT_PULLUP); // setting PF.0 Pin as input with pull up
    pinMode(PF_4, INPUT_PULLUP); // setting PF.4 Pin as input with pull up
}
void loop() {
    if(!digitalRead(PF_0)) //checking for logic zero
    {
        digitalWrite(PF_3, HIGH);   // turn the GREEN LED on
        delay(1000);               // wait for a second
        digitalWrite(PF_3, LOW);   // turn the GREEN LED off by making the voltage LOW
    }
    if(!digitalRead(PF_4)) //checking for logic zero
    {
        digitalWrite(PF_2, HIGH);   // turn the BLUE LED on
        delay(1000);               // wait for a second
        digitalWrite(PF_2, LOW);   // turn the BLUE LED off by making the voltage LOW
    }
}
See also
SENSORS