• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomeStarter Kit for pcDuino8 Uno User Guide3.C Language and Arduino type IDE for pcDuino8 Uno3.2.Arduino library and samples3.2.4.GPIO
Previous Next

3.2.4.GPIO

Posted by: Olva , August 10, 2016

Reference functions

  1. pinMode()
  2. digitalRead()
  3. digitalWrite()
  4. pulseIn()

Sample

Turn on or off LED by pressing and releasing the button connected to the GPIO.

Connect

Sample code

int led_pin = 5;
/*
* Button LED test program
*/

#include <core.h>

int led_pin = 13;
int btn_pin = 6;

void setup() {
    if ( argc == 3 ) {
        btn_pin = atoi(argv[1]);
        led_pin = atoi(argv[2]);
    }
//set the gpio to input or output mode
    pinMode(led_pin, OUTPUT);
    pinMode(btn_pin, INPUT);
}

void loop() {
//press btn_pin to turn on LED
    int value = digitalRead(btn_pin);
    if ( value == HIGH )
    { // button pressed
        digitalWrite(led_pin, HIGH); // turn on LED
    } else { // button released
        digitalWrite(led_pin, LOW); // turn off LED
    }

    delay(100);
}

Share!
Tweet

Olva

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors