Hi,
I have the following code which enables the built in led ( I have removed blink.sh aside for now)
#!/bin/sh
# Example Pins
BUILTIN_LED_PIN=509
LED_GPIO=/sys/class/gpio/gpio${BUILTIN_LED_PIN}
if test -d ${LED_GPIO}; then
echo "PIN ${BUILTIN_LED_PIN} already exported"
else
echo ${BUILTIN_LED_PIN} > /sys/class/gpio/export
fi
echo out > ${LED_GPIO}/direction
echo 1 > ${LED_GPIO}/value
while true; do
sleep 0.5
done
It turns on the led as expected, but this C program using wiringx does not turn on the builtin led:
#include <stdio.h>
#include <unistd.h>
#include <wiringx.h>
#include <termios.h>
#define LED_PIN 29 // 509 (BUILTIN_LED)
char get_keypress()
{
struct termios oldt, newt;
char ch;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}
0
int main()
{
if (wiringXSetup("milkv_duos", NULL) == -1)
{
printf("Failed to initialize WiringX.\n");
return 1;
}
pinMode(LED_PIN, PINMODE_OUTPUT);
printf("Press any key to turn on the Built-in LED...\n");
get_keypress();
// Turn LED ON
digitalWrite(LED_PIN, HIGH);
printf("Built-in LED is now ON!\n");
while (1)
{
sleep(1);
}
return 0;
}
I see other issues on other pins also when the shell script can enable an output on a pin, but the C program using wiringx briefly flashes the led on.
Any ideas why this is happening?