/* * pins.h * * Created on: Jan 31, 2015 * Author: nomore */ #ifndef PINS_H_ #define PINS_H_ #include #include #include #include #include #include #include "mraa.h" void delay(int milliseconds); bool PinPulse(int pin, int time){ mraa_result_t r = MRAA_SUCCESS; mraa_init(); mraa_gpio_context gpio; gpio = mraa_gpio_init(pin); if ( gpio == NULL ) { fprintf(stderr, "Error opening GPIO\n"); exit(1); } r = mraa_gpio_dir(gpio, MRAA_GPIO_OUT); if ( r != MRAA_SUCCESS ) { mraa_result_print(r); mraa_result_print(r); } //turn on r = mraa_gpio_write(gpio, 1); if ( r != MRAA_SUCCESS) { mraa_result_print(r); } delay(time); //turn off r = mraa_gpio_write(gpio, 0); if ( r != MRAA_SUCCESS) { mraa_result_print(r); } /* Clean up GPIO and exit */ r = mraa_gpio_close(gpio); if ( r != MRAA_SUCCESS ) { mraa_result_print(r); } } void delay(int milliseconds) { long pause; clock_t now,then; pause = milliseconds*(CLOCKS_PER_SEC/1000); now = then = clock(); while( (now-then) < pause ) now = clock(); } #endif /* PINS_H_ */