I'm following the instructions at http://wiringpi.com/reference/priority-interrupts-and-threads/ using the PI_THREAD and piThreadCreate(myThread) methods and cannot get the LED(s) to blink. Here's the code I'm using:
/*
* c_pins_01.c
*
* Toggle GPIO pins on/off using threads.
*/
/*
* includes
*/
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>
/*
* Global constants and variables.
*/
// GPIO pins used
unsigned char pins[] = { 13, 19, 26, 6, 5 },
*p_pins = &pins[0];
#define MAX_PINS(p) (sizeof(p) / sizeof(p[0]))
// Delay
#define DELAY 500
/*
* Pin toggling threads.
*/
PI_THREAD(toggle_pin_13) {
while(1) {
digitalWrite(13, LOW);
delay(DELAY);
digitalWrite(13, HIGH);
}
return(0);
}
PI_THREAD(toggle_pin_16) {
while(1) {
digitalWrite(16, LOW);
delay(DELAY);
digitalWrite(16, HIGH);
}
return(0);
}
/*
* Main function.
*/
int main(int argc, char **argv) {
printf("Hello woild from the C programming language!\n");
printf("Raspberry Pi 3 B board revision: %d\n\n", piBoardRev());
wiringPiSetupGpio();
for (int i = 0; i < MAX_PINS(pins); i++) {
pinMode(pins[i], OUTPUT);
digitalWrite(pins[i], HIGH);
}
int t = piThreadCreate(toggle_pin_13);
if (t != 0) {
printf("Thread did not start.\n");
}
t = piThreadCreate(toggle_pin_16);
if (t != 0) {
printf("Thread did not start.\n");
}
/*
while(1) {
for (int i = 0; i < MAX_PINS(pins); i++) {
digitalWrite(pins[i], LOW);
}
delay(DELAY);
for (int i = 0; i < MAX_PINS(pins); i++) {
digitalWrite(pins[i], HIGH);
}
delay(DELAY);
}
*/
return(0);
} /* End main() */
And it's not working. The program compiles fine but when executed, the LEDs don't toggle on/off.
Any assistance would be greatly appriceated.
the LEDs don't toggle on/off... are we supposed to guess what the LEDs actually do? – jsotola Jun 03 '18 at 23:13