Ejemplo n.º 1
0
int main(void)
{
//initialise pigio and pins
    if (gpioInitialise() < 0 )
    {
        printf("pigpio initialise failed\n");
        return 1;
    }

    gpioSetMode(BLUE, PI_OUTPUT);
    gpioSetMode(RED, PI_OUTPUT);
    gpioSetMode(GREEN, PI_OUTPUT);
    gpioSetPWMrange(BLUE, 200);
    gpioSetPWMrange(RED, 200);
    gpioSetPWMrange(GREEN, 200);


    pthread_t pth;  // this is our thread identifier

    pthread_create(&pth,NULL,threadFunc,NULL);

    int i;

    while(1) {
        if(MODE != 0) {
            for (i=0; i<201; i++) {
                if (MODE == 1) {
                    sLED(0,0,i,1);
                    usleep(20000);
                }
                else if(MODE == 2) {
                    sLED(i,i/2,i/4,1);
                    usleep(20000);
                }
                else if(MODE == 0) {
                    break;
                }
            }
            sleep(1);
            for(i=200; i>=0; i--) {
                if(MODE == 1) {
                    sLED(0,0,i,1);
                    usleep(20000);
                }
                else if(MODE == 2) {
                    sLED(i,i/2,i/4,1);
                    usleep(20000);
                }
                else if(MODE == 0) {
                    break;
                }
            }
        }
    }
    pthread_join(pth,NULL);

    return 1;
}
Ejemplo n.º 2
0
void ESCController::initialize(int controlled_esc[4], int ESCSanity[4], int frequency, int min, int max)
{
    for (int i=0;i<4;i++) {
        ESC[i] = controlled_esc[i];
        gpioSetPWMfrequency(ESC[i], frequency);
        gpioSetPWMrange(ESC[i], 1000000/frequency);
        sanity[i] = ESCSanity[i];
    }
    outMin = min;
    outMax = max;
}
Ejemplo n.º 3
0
void mygpioSetup() {
    if (gpioGetMode(18) != PI_OUTPUT) {
        (gpioSetMode(18, PI_OUTPUT));
    }
    if (gpioGetMode(17) != PI_OUTPUT) {
        (gpioSetMode(17, PI_OUTPUT));
    }
    if (gpioGetPWMrange(18) != 2000) {
        (gpioSetPWMrange(18, 2000));
    }
    if (gpioGetPWMrange(17) != 2000) {
        (gpioSetPWMrange(17, 2000));
    }
    if (gpioGetPWMfrequency(18) != 8000) {
        (gpioSetPWMfrequency(18, 8000));
    }
    if (gpioGetPWMfrequency(17) != 8000) {
        (gpioSetPWMfrequency(17, 8000));
    }
}
/*
 * Class:     com_diozero_pigpioj_PigpioGpio
 * Method:    setPWMRange
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_com_diozero_pigpioj_PigpioGpio_setPWMRange
  (JNIEnv* env, jclass clz, jint gpio, jint range) {
	return gpioSetPWMrange(gpio, range);
}