-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotter_code.ino
105 lines (96 loc) · 2.41 KB
/
plotter_code.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <Servo.h>
uint8_t buffer[20]; //Buffer needed to store data packet for transmission
int16_t data1 = 1;
int16_t data2 = 2;
int16_t data3 = 3;
int16_t data4 = 4;
bool debug = false;
uint8_t buffer2[20];
Servo myservo; // create servo object to control a servo
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
myservo.attach(9,600,2600); // (pin, min, max) For Alignment
}
// or for example
// case 0:
// int sensorValueOrX = digitalRead(0);
// Serial.print(sensorValueOrX);
// break;
// put your main code here, to run repeatedly:
void loop(){
for (uint8_t i = 0; i<7; i++) {
switch (i) {
case 0:
myservo.write(0);
Serial.print(0); // digitalRead the pin
delay(100);
break;
case 1:
myservo.write(45);
Serial.print(45); // digitalRead the pin
delay(100);
break;
case 2:
myservo.write(90);
Serial.print(90); // digitalRead the pin
delay(100);
break;
case 3:
myservo.write(180);
Serial.print(180); // digitalRead the pin
delay(1000);
break;
case 4:
myservo.write(0);
Serial.print(0); // digitalRead the pin
delay(1000);
break;
case 5:
myservo.write(45);
Serial.print(45); // digitalRead the pin
delay(100);
break;
case 6:
myservo.write(90);
Serial.print(90); // digitalRead the pin
delay(100);
break;
}
if (i < 8)
Serial.print(" ");
}
Serial.print('\r');
delay(5);
}
uint8_t variableA = {0x00};
void plot(int16_t data1, int16_t data2, int16_t data3, int16_t data4) {
int16_t pktSize;
buffer[0] = 0xCDAB; //SimPlot packet header. Indicates start of data packet
//buffer[1] = 4*sizeof(int16_t); //Size of data in bytes. Does not include the header and size fields
buffer[1] = 1;
buffer[2] = 5;
buffer[3] = 6;
buffer[4] = 7;
buffer[5] = 8;
pktSize = 2 + 2 + (4*sizeof(int16_t)); //Header bytes + size field bytes + data
if (!debug) {
Serial.print(data1);
Serial.print(" ");
Serial.print(data2);
Serial.print(" ");
Serial.print(data3);
Serial.print(" ");
Serial.print(data4);
Serial.print('\r');
}
else {
Serial.print("Size: ");
Serial.println(pktSize, HEX);
for (int i = 0; i<pktSize; i++) {
Serial.print(buffer[i], HEX);
Serial.print(" ");
}
Serial.println();
}
}