Exemplo n.º 1
0
void Control::demo(){
    float millis = 1.0;
    int tick = calcTicks(millis, HERTZ);
    while(1){
        pwmWrite(PIN_BASE + 16, tick);
        delay(2000);
        millis=1.6;
        tick = calcTicks(millis, HERTZ);
        pwmWrite(PIN_BASE + 16, tick);         delay(2000);
        millis=1.0;
        tick = calcTicks(millis, HERTZ);
        pwmWrite(PIN_BASE + 16, tick);
        delay(2000);
    }
}
Exemplo n.º 2
0
void Control::adjustMotorSpeed(int motor, double speed){
    double milliseconds = speed*(MaxTime-MinTime)+MinTime;
    milliseconds = inputNormalizer(milliseconds, MinTime, MaxTime);
    //printf("Milliseconds: %f", milliseconds);
    double tick = calcTicks(milliseconds, HERTZ);
    pwmWrite(PIN_BASE + motor, tick);
}
Exemplo n.º 3
0
int main(void)
{
	printf("PCA9685 servo example\n");
	printf("Connect a servo to any pin. It will rotate to random angles\n");

	// Setup with pinbase 300 and i2c location 0x40
	int fd = pca9685Setup(PIN_BASE, 0x40, HERTZ);
	if (fd < 0)
	{
		printf("Error in setup\n");
		return fd;
	}

	// Reset all output
	pca9685PWMReset(fd);


	// Set servo to neutral position at 1.5 milliseconds
	// (View http://en.wikipedia.org/wiki/Servo_control#Pulse_duration)
	float millis = 1.5;
	int tick = calcTicks(millis, HERTZ);
	pwmWrite(PIN_BASE + 16, tick);
	delay(2000);


	int active = 1;
	while (active)
	{
		// That's a hack. We need a random number < 1
		float r = rand();
		while (r > 1)
			r /= 10;

		millis = map(r, 1, 2);
		tick = calcTicks(millis, HERTZ);

		pwmWrite(PIN_BASE + 16, tick);
		delay(1000);
	}

	return 0;
}
Exemplo n.º 4
0
int main(void)
{
	printf("PCA9685 User-defined signal generation for KK2\n");

	// Setup with pinbase 300 and i2c location 0x40
	int fd = pca9685Setup(PIN_BASE, 0x40, 1/PERIOD);
	if (fd < 0)
	{
		printf("Error in setup\n");
		return fd;
	}

	// Reset all output
	pca9685PWMReset(fd);
	
	int cmd = 1;
	float dutytime = MIN_DUTY;
	int dutyTicks = 0;
	int channel = 0;
	while(cmd != 0){
		printMenu();
		printf("Select an option: ");
		cmd = getchar()-'0';
		switch(cmd){
			case 1:
				printf("Select channel: ");
				getchar();
				channel = getchar()-'0';
				printf("Testing 1.25ms...\n");
				//setPWMSignal(channel, PERIOD, 0.0);
				//dutytime = map(0.5, , 1.25);
				dutyTicks = calcTicks(1.25, PERIOD);
				printf("dutyTicks = %d\n", dutyTicks);
				pwmWrite(PIN_BASE, dutyTicks);
				delay(2000);
				printf("Testing 1.50ms...\n");
				//dutytime = map(0, 1.5, 1.5);
				//setPWMSignal(channel, PERIOD, 0.5);
				dutyTicks = calcTicks(1.50, PERIOD);
				printf("dutyTicks = %d\n", dutyTicks);
				pwmWrite(PIN_BASE, dutyTicks);
				delay(2000);
				printf("Testing 1.75ms...\n");
				//dutytime = map(0, 1.75, 1.75);
				//setPWMSignal(channel, PERIOD, 1.0);
				dutyTicks = calcTicks(1.75, PERIOD);
				printf("dutyTicks = %d\n", dutyTicks)
				pwmWrite(PIN_BASE, dutyTicks);
				delay(2000);
			break;
			case 2:
			break;
			default:
			break;
		}
	}

	// Set servo to neutral position at 1.5 milliseconds
	// (View http://en.wikipedia.org/wiki/Servo_control#Pulse_duration)
	/*float millis = 1.5;
	int tick = calcTicks(millis, HERTZ);
	pwmWrite(PIN_BASE, tick);
	delay(2000);


	int active = 1;
	while (active)
	{
		// That's a hack. We need a random number < 1
		float r = rand() /(rand() * 10);
		//while (r > 1)
		//	r /= 10;
		printf("r: %lf\n", r);
		millis = map(r, 1.25, 1.75);
		printf("millis: %lf\n", millis);
		tick = calcTicks(millis, HERTZ);
		printf("tick: %d\n", tick);

		pwmWrite(PIN_BASE, tick);
		delay(1000);
	}*/

	return 0;
}
Exemplo n.º 5
0
void setPWMSignal(int channel, float period, float duty){
	int ticks = calcTicks(map(duty,MIN_DUTY,MAX_DUTY), 1/period);
	pwmWrite(PIN_BASE+channel, ticks);
	//delay(period*1000);
}