#include #include #include #include //setup GPIO Direction folder const char *gpio10_dir= "/sys/class/gpio/gpio26/direction"; const char *gpio10_val= "/sys/class/gpio/gpio26/value"; /* Light On - Light-Off*/ //create a variable to store whether we are sending a '1' or a '0' char set_value[4]; FILE *fp; /******************************************* * Light on/off * *******************************************/ void light_On(){ char set_value[4]; /*start motion pins*/ if ((fp = fopen(gpio10_val, "rb+")) == NULL) { printf("Cannot open value file \n"); exit(1); } //Set pointer to beginning of the file rewind(fp); //Write our value of "1" to the file strcpy(set_value,"1"); fwrite(&set_value, sizeof(char), 1, fp); fclose(fp); } void light_Off(){ char set_value[4]; /*start motion pins*/ if ((fp = fopen(gpio10_val, "rb+")) == NULL) { printf("Cannot open value file \n"); exit(1); } //Set pointer to beginning of the file rewind(fp); //Write our value of "1" to the file strcpy(set_value,"0"); fwrite(&set_value, sizeof(char), 1, fp); fclose(fp); } void set_direction(const char *dir, int size){ char set_value[4]; //SET DIRECTION //Open the LED's sysfs file in binary for reading and writing, store file pointer in fp if ((fp = fopen(dir, "rb+")) == NULL) { printf("Cannot open direction file \n"); exit(1); } //Set pointer to beginning of the file rewind(fp); //Write our value of "out" to the file strcpy(set_value,"out"); fwrite(&set_value, sizeof(char), size, fp); fclose(fp); } void pin_value(const char *dir, char vset_value[]){ //Open the LED's sysfs file in binary for reading and writing, store file pointer in fp if ((fp = fopen(dir, "rb+")) == NULL) { printf("Cannot open value file \n"); exit(1); } //Set pointer to beginning of the file rewind(fp); fwrite(&vset_value, sizeof(char), 1, fp); fclose(fp); } int light() { //create a variable to store whether we are sending a '1' or a '0' char set_value[4]; if ((fp = fopen("/sys/class/gpio/export", "ab")) == NULL) { printf("Cannot open export file \n"); exit(1); } rewind(fp); //export DAC GPIO 10 strcpy(set_value,"26"); fwrite(&set_value, sizeof(char), 2, fp); fclose(fp); strcpy(set_value,"0"); //setup GPIO 1 set_direction(gpio10_dir, 3); light_On(); return 0; } int main() { printf("Status: 204 No Content \n"); light(); return 0; }