Skip to content

Commit 7e812fe

Browse files
committed
need to be test: changed exemples
1 parent 30e2ca1 commit 7e812fe

13 files changed

Lines changed: 264 additions & 204 deletions

File tree

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
#include "Arduino.h"
22
#include <Pelco_And_Arduino.h>
33

4-
PelcoBus MyPelcoBus(6, // TX pin (Arduino to Cam)
5-
7, // RX pin (Cam to Arduino)
6-
8); // RE pin for manual switching modules set to -1 if it is a auto module (like a groove one)
4+
PelcoBus MyPelcoBus(6, // RX pin (Cam to Arduino)
5+
7, // TX pin (Arduino to Cam)
6+
8); // RE pin for manual switching modules set to -1 or nothing if it is a auto module (like a groove one)
77

8-
PelcoBus::PelcoCam Camera1; //Declare a camera
8+
9+
PelcoCam Camera1(&MyPelcoBus, //The pointer to the bus
10+
1, //Address of the camera
11+
false); //We are getting a response
912

1013
void setup() {
1114
Serial.begin(9600);
1215

13-
// Begin the serial communication
16+
// Begin the bus communication at 9600 and enable logging
1417
MyPelcoBus.begin(PELCO_D9600, true);
1518

16-
// Set camera settings
17-
Camera1.address = 1; //Address of the camera
18-
Camera1.disable_ack = false; //For this exemple, this must set to false!
19-
20-
21-
// Send stop, send_command will return a bool that indicates if the cameras sended its ACK
22-
// It's a good way to see if the camera is plugged in
23-
while (!MyPelcoBus.send_command(Camera1, STOP)) {
19+
//Is the camera online?
20+
while (!Camera1.available()) {
2421
Serial.println("Camera not plugged?");
2522
delay(1000);
2623
}
2724
Serial.println("Init Finished!");
2825
}
2926

3027
void loop() {
31-
MyPelcoBus.send_command(Camera1, PAN_L, 0x3F); // Spin for a random time
32-
delay(random(1000, 2000));
28+
Camera1.send_command(SET_PAN, random(0, 35999)); // set pan to a random angle
3329

34-
int angle100 = MyPelcoBus.send_request(Camera1, QUERY_PAN); // Get the current angle of the camera
30+
int angle100 = Camera1.send_request(QUERY_PAN); // Get the current angle of the camera
3531

3632
float angle = angle100 / 100.0; // Convert to float
3733

3834
Serial.println("Angle detected: " + String(angle));
35+
delay(200);
3936
}

examples/old_model/old_model.ino

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
#include "Arduino.h"
22
#include <Pelco_And_Arduino.h>
33

4-
PelcoBus MyPelcoBus(6, // TX pin (Arduino to Cam)
5-
7, // RX pin (Cam to Arduino)
6-
8); // RE pin for manual switching modules set to -1 if it is a auto module (like a groove one)
4+
PelcoBus MyPelcoBus(6, // RX pin (Cam to Arduino)
5+
7, // TX pin (Arduino to Cam)
6+
8); // RE pin for manual switching modules set to -1 or nothing if it is a auto module (like a groove one)
77

8-
PelcoBus::PelcoCam Camera1; //Declare a camera
8+
////IMPORTANT: Even if it is an old model without returning a response capabilities you need to specify a RX pin and a RE pin
9+
10+
PelcoCam Camera1(&MyPelcoBus, //The pointer to the bus
11+
1, //Address of the camera
12+
true); //We are NOT getting a response
913

1014
void setup() {
1115
Serial.begin(9600);
1216

13-
// Begin the serial communication
17+
// Begin the bus communication at 9600 and enable logging
1418
MyPelcoBus.begin(PELCO_D9600, true);
1519

16-
// Set camera settings
17-
Camera1.address = 1; //Address of the camera
18-
Camera1.disable_ack = true; //Old models function one 2 pair of wires and only one is usable, the TX one, so it's impossible that it can send back a reqponse
19-
20-
21-
// Send stop, send_command will return a bool that indicates if the cameras sended its ACK
22-
// It's a good way to see if the camera is plugged in
23-
while (!MyPelcoBus.send_command(Camera1, STOP)) {
20+
//Is the camera online? this will fail because it is an old models
21+
while (!Camera1.available()/* <---- will fail! */) {
2422
Serial.println("Camera not plugged?");
2523
delay(1000);
2624
}
@@ -30,13 +28,13 @@ void setup() {
3028
void loop() {
3129

3230
//Pan to the left with max speed before turbo
33-
MyPelcoBus.send_command(Camera1, PAN_L, 0x3F);
31+
Camera1.send_command(PAN_L, 0x3F);
3432
delay(1000);
35-
MyPelcoBus.send_command(Camera1, STOP); //Stop the camera
33+
Camera1.send_command(STOP); //Stop the camera
3634
delay(1000);
3735
//Pan to the left with less speed than the tilt speed that goes up
38-
MyPelcoBus.send_command(Camera1, PAN_R, 0x3F);
36+
Camera1.send_command(PAN_R, 0x3F);
3937
delay(1000);
40-
MyPelcoBus.send_command(Camera1, STOP); //Stop the camera
38+
Camera1.send_command(STOP); //Stop the camera
4139
delay(1000);
4240
}

examples/send_raw/send_raw.ino

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#include "Arduino.h"
22
#include <Pelco_And_Arduino.h>
33

4-
PelcoBus MyPelcoBus(6, // TX pin (Arduino to Cam)
5-
7, // RX pin (Cam to Arduino)
6-
8); // RE pin for manual switching modules set to -1 if it is a auto module (like a groove one)
4+
PelcoBus MyPelcoBus(6, // RX pin (Cam to Arduino)
5+
7, // TX pin (Arduino to Cam)
6+
8); // RE pin for manual switching modules set to -1 or nothing if it is a auto module (like a groove one)
77

8-
void setup() {
9-
//Here we don't need to declare a camera because all we send is raw
108

9+
//No need to declare a camera here
10+
11+
void setup() {
1112
Serial.begin(9600);
1213

13-
// Begin the serial communication
14+
// Begin the bus communication at 9600 and enable logging
1415
MyPelcoBus.begin(PELCO_D9600, true);
1516

1617
Serial.println("Init Finished!");

examples/set_position/set_position.ino

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
#include "Arduino.h"
22
#include <Pelco_And_Arduino.h>
33

4-
PelcoBus MyPelcoBus(6, // TX pin (Arduino to Cam)
5-
7, // RX pin (Cam to Arduino)
6-
8); // RE pin for manual switching modules set to -1 if it is a auto module (like a groove one)
4+
PelcoBus MyPelcoBus(6, // RX pin (Cam to Arduino)
5+
7, // TX pin (Arduino to Cam)
6+
8); // RE pin for manual switching modules set to -1 or nothing if it is a auto module (like a groove one)
77

8-
PelcoBus::PelcoCam Camera1; //Declare a camera
8+
9+
PelcoCam Camera1(&MyPelcoBus, //The pointer to the bus
10+
1, //Address of the camera
11+
false); //We are getting a response
912

1013
void setup() {
1114
Serial.begin(9600);
1215

13-
// Begin the serial communication
16+
// Begin the bus communication at 9600 and enable logging
1417
MyPelcoBus.begin(PELCO_D9600, true);
1518

16-
// Set camera settings
17-
Camera1.address = 1; //Address of the camera
18-
Camera1.disable_ack = false; //If you want to disable the ACK, set it to true
19-
20-
21-
// Send stop, send_command will return a bool that indicates if the cameras sended its ACK
22-
// It's a good way to see if the camera is plugged in
23-
while (!MyPelcoBus.send_command(Camera1, STOP)) {
19+
//Is the camera online?
20+
while (!Camera1.available()) {
2421
Serial.println("Camera not plugged?");
2522
delay(1000);
2623
}
@@ -30,7 +27,7 @@ void setup() {
3027
void loop() {
3128
//loops the camera increment angle of 1°; very fun because it shakes like hell
3229
for(int i=0; i<35999; i=i+100){
33-
MyPelcoBus.send_command(Camera1, SET_PAN, i); //Hundered of degrees, max is 35999 == 359,99°
30+
Camera1.send_command(SET_PAN, i); //Hundered of degrees, max is 35999 == 359,99°
3431
delay(500);
3532
}
3633

examples/simple/simple.ino

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
#include "Arduino.h"
22
#include <Pelco_And_Arduino.h>
33

4-
PelcoBus MyPelcoBus(6, // TX pin (Arduino to Cam)
5-
7, // RX pin (Cam to Arduino)
6-
8); // RE pin for manual switching modules set to -1 if it is a auto module (like a groove one)
4+
PelcoBus MyPelcoBus(6, // RX pin (Cam to Arduino)
5+
7, // TX pin (Arduino to Cam)
6+
8); // RE pin for manual switching modules set to -1 or nothing if it is a auto module (like a groove one)
77

8-
PelcoBus::PelcoCam Camera1; //Declare a camera
8+
9+
PelcoCam Camera1(&MyPelcoBus, //The pointer to the bus
10+
1, //Address of the camera
11+
false); //We are getting a response
912

1013
void setup() {
1114
Serial.begin(9600);
1215

13-
// Begin the serial communication
16+
// Begin the bus communication at 9600 and enable logging
1417
MyPelcoBus.begin(PELCO_D9600, true);
1518

16-
// Set camera settings
17-
Camera1.address = 1; //Address of the camera
18-
Camera1.disable_ack = false; //If you want to disable the ACK, set it to true
19-
20-
21-
// Send stop, send_command will return a bool that indicates if the cameras sended its ACK
22-
// It's a good way to see if the camera is plugged in
23-
while (!MyPelcoBus.send_command(Camera1, STOP)) {
19+
//Is the camera online?
20+
while (!Camera1.available()) {
2421
Serial.println("Camera not plugged?");
2522
delay(1000);
2623
}
@@ -29,13 +26,13 @@ void setup() {
2926

3027
void loop() {
3128
//Pan to the left with max speed before turbo
32-
MyPelcoBus.send_command(Camera1, PAN_L, 0x3F);
29+
Camera1.send_command(PAN_L, 0x3F);
3330
delay(1000);
34-
MyPelcoBus.send_command(Camera1, STOP); //Stop the camera
31+
Camera1.send_command(STOP); //Stop the camera
3532
delay(1000);
3633
//Pan to the left with less speed than the tilt speed that goes up
37-
MyPelcoBus.send_command(Camera1, PAN_R, 0x3F);
34+
Camera1.send_command(PAN_R, 0x3F);
3835
delay(1000);
39-
MyPelcoBus.send_command(Camera1, STOP); //Stop the camera
36+
Camera1.send_command(STOP); //Stop the camera
4037
delay(1000);
4138
}

0 commit comments

Comments
 (0)