Triggering PCA9685 with a button?

What's up, People Who Are Way Smarter Than I'll Ever Be? :stuck_out_tongue:

I'm building a PCA9685-controlled Nerf target range, and I've got the code all set up to rotate each servo the correct number of degrees.

The problem is, the servos just do it on a loop. I want to trigger the process with a button, have it run through each servo once, and then stop until I press the button again.

Can't seem to figure out how!! Any help would be massively appreciated!

(deleted)

Ha!! Sorry.

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define SERVOMIN 150 // This is the ‘minimum’ pulse length count (out of 4096)
#define SERVOMAX 600 // This is the ‘maximum’ pulse length count (out of 4096)
#define SERVO_FREQ 60 // Analog servos run at ~60 Hz updates

// our servo # counter
uint8_t servonum = 0;

void setup() {
Serial.begin(9600);
Serial.println(“10 channel servo test!”);

pwm.begin();

pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates

delay(10);
}

void loop() {
//set (servo to be used, nothing, angle)

pwm.setPWM(0, 0, 150);
delay(500);
pwm.setPWM(0, 0, 200);
delay(500);
pwm.setPWM(1, 0, 150);
delay(500);
pwm.setPWM(1, 0, 200);
delay(500);

}

spycatcher2k:
Sorry, I can’t help, the code you posted won’t compile.

Ha!! Sorry. Not too good at this, as you can tell.

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define SERVOMIN 150 // This is the ‘minimum’ pulse length count (out of 4096)
#define SERVOMAX 600 // This is the ‘maximum’ pulse length count (out of 4096)
#define SERVO_FREQ 60 // Analog servos run at ~60 Hz updates

// our servo # counter
uint8_t servonum = 0;

void setup() {
Serial.begin(9600);
Serial.println(“10 channel servo test!”);

pwm.begin();

pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates

delay(10);
}

void loop() {
//set (servo to be used, nothing, angle)

pwm.setPWM(0, 0, 150);
delay(500);
pwm.setPWM(0, 0, 200);
delay(500);
pwm.setPWM(1, 0, 150);
delay(500);
pwm.setPWM(1, 0, 200);
delay(500);

}

(deleted)

spycatcher2k:
Connect a button between pin 2 and GND.

I'll see if I can figure that out, thanks. Being a newbie is tough.

In the meantime, the code gives an error that "while" was not declared in that scope.

Thoughts?

JG

No it actually says "While was not....." and that's because it should be spelled "while". C++ is case sensitive but even the experts have typo problems from time to time.

Steve

slipstick:
No it actually says "While was not....." and that's because it should be spelled "while". C++ is case sensitive but even the experts have typo problems from time to time.

Steve

Good god, what use are my meager skills in the face of such pedantic code requirements!?! :stuck_out_tongue:

Nice catch, Steve, thanks.