[vc_row][vc_column width=”1/1″][vc_column_text]
This demo uses tilt module to control LED.
[/vc_column_text][vc_tour][vc_tab title=”Hardware list” tab_id=”1450922301-1-18″][vc_column_text]
- 96board
- Liner Base Mezzanine Card
- LED module of Linker kit
- Tilt module of Linker kit
- 4-pin cable x 2
[/vc_column_text][/vc_tab][vc_tab title=”Steps” tab_id=”1450922301-2-15″][vc_column_text]
Connect
Connect LED module to D2 port Linker Base Mezzanine Card on and tilt module to D1 port.
[/vc_column_text][/vc_tab][vc_tab title=”Program” tab_id=”1450922327852-2-10″][vc_column_text]
#include <stdio.h> #include <stdlib.h> #include "libsoc_gpio.h" #include "libsoc_debug.h" #define GPIO_LED 13 #define GPIO_SKEW 36 int main() { gpio *gpio_led,*gpio_skew; libsoc_set_debug(1); gpio_led = libsoc_gpio_request(GPIO_LED,LS_SHARED); gpio_skew = libsoc_gpio_request(GPIO_SKEW,LS_SHARED); if((gpio_led == NULL) || (gpio_skew == NULL)) { goto fail; } libsoc_gpio_set_direction(gpio_led,OUTPUT); libsoc_gpio_set_direction(gpio_skew,INPUT); if((libsoc_gpio_get_direction(gpio_led) != OUTPUT) || (libsoc_gpio_get_direction(gpio_skew) != INPUT)) { goto fail; } while(1) { int n = libsoc_gpio_get_level(gpio_skew); if(n == HIGH) { libsoc_gpio_set_level(gpio_led,HIGH); } else { libsoc_gpio_set_level(gpio_led,LOW); } sleep(1); } fail: if(gpio_led || gpio_skew) { printf("apply gpio resource fail!\n"); libsoc_gpio_free(gpio_led); libsoc_gpio_free(gpio_skew); } return EXIT_SUCCESS; }
[/vc_column_text][/vc_tab][vc_tab title=”Compile and run” tab_id=”1450922328866-3-5″][vc_column_text]
gcc Skew_Control_Led.c -o Skew_Control_Led -lsoc sudo ./Skew_Control_Led
Change the position of tilt module, and check the LED’s state.
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.