Things used in this project

Hardware components:
FriendlyARM NanoPi NEO Air
×1
09590 01
LED (generic)
×1

Schematics

Wiring LED
Schematic led ixmrvlpkbn

Code

led.cC/C++
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "libfahw.h"

#define STATUS_CHANGE_TIMES		20

int main(int argc, char **argv)
{
	int i;
	int intValue = 0;
	int pin = GPIO_PIN(7);  //LED connected to Pin number 7
            
	if (boardInit() < 0)
	{
		printf("Fail to init board\n");
        return -1;
	}
            
	if (exportGPIOPin(pin) != 0)
	{
		printf("exportGPIOPin(%d) failed\n", pin);
	}
            
    if(setGPIODirection(pin, GPIO_OUT) == -1)
    {
        printf("setGPIODirection(%d) failed\r\n",pin);
	}
            
	for(i = 0; i < STATUS_CHANGE_TIMES; i++)
	{
		intValue ^= 1;		//0 xor 1 = 1, 1 xor 1 = 0
		if(setGPIOValue(pin, intValue) > 0)
		{
			printf("%d - GPIO_PIN(%d) value is %d\r\n",i+1, pin, intValue);
		}
		else
		{
			printf("setGPIOValue(%d) failed\r\n", pin);
		}
		usleep(500000);
	}
           
	unexportGPIOPin(pin);
	return 0;
}

Credits

48950.jpg
Ramin Sangesari
11 projects • 179 followers
Programmer and IoT Developer
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog