Digital output: LED blinking

From openPicus Wiki
Jump to: navigation, search

Contents

What you are going to learn

This tutorial shows how Flyport can drive a LED by a GPIO.

Introduction to GPIO

GPIO (General Purpose IO) are pins to interface an embedded system to external digital devices. A GPIO pin can be configured both as input or output. For example a GPIO can drive a led or read the state of a button.


How to use it

Flyport PRO

In this tutorial we explain how to cyclically turn on and off a LED, using LED-p31 of evaluation board.

Code Example

The functions used in this tutorial are the following:

Name Function Description
 void IOInit (int io, int putval) Initializes the specified pin with the desired function. Remappable pins allow the user to set the pin not just as input or output, but also with advanced functionalities, as such UART or SPI.
 void IOPut (int io, int putval) Puts the putval value on the specified IO output pin.


Source code for taskFlyport.c:

#include "taskFlyport.h"
void FlyportTask()
{
  int i;
  for(i = 0; i < 9; i++)
      ADCDetach(i);
  ADCAttach(2);    // Enable only Analog 2 channel (pin p5)
 
  IOInit(p31,out);           // Initializes pin 31 as output
 
  // First blink (long) to show how to turn ON and OFF the LED  
  IOPut(p31, on);
  vTaskDelay(100);
  IOPut(p31, off);
  vTaskDelay(100);
 
  while(1)
  {
      IOPut(p31, toggle);   // Changes the status of the pin
      vTaskDelay(50);      // Inserts a 0.5 seconds delay	
  }
}


Flyport

In this tutorial we explain how to cyclically turn on and off a LED, using pin 9.
Flyport offers up to 18 Digital GPIO on the common connector J1 that users can customize by firmware. openPicus APIs are a set of easy-to-use instructions that do not require a deep knowledge of embedded programming.


Bill of Materials

  • 1x Flyport Module
  • 1x miniUSB programmer
  • 1x LED
  • 1x Resistor (330 Ohm)
  • 1x Proto Nest Board
  • 1x Breadboard


Schematic

DoutSchematic.png


DigitalOut Image.jpg

Code example


The functions used in this tutorial are the following:

Name Function Description
 void IOInit (int io, int putval) Initializes the specified pin with the desired function. Remappable pins allow the user to set the pin not just as input or output, but also with advanced functionalities, as such UART or SPI.
 void IOPut (int io, int putval) Puts the putval value on the specified IO output pin.


Source code for taskFlyport.c:

#include "taskFlyport.h"
void FlyportTask()
{
  IOInit(p9,out);           // Initializes pin 9 as output
 
  // First blink (long) to show how to turn ON and OFF the LED  
  IOPut(p9, on);
  vTaskDelay(100);
  IOPut(p9, off);
  vTaskDelay(100);
 
  while(1)
  {
      IOPut(p9, toggle);   // Changes the status of the pin
      vTaskDelay(50);      // Inserts a 0.5 seconds delay	
  }
}
Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox