... | ... |
@@ -13,6 +13,16 @@ int posTilt = A0; |
13 | 13 |
int posPan = A1; |
14 | 14 |
int motorSpeedStat = 0; |
15 | 15 |
|
16 |
+int speedStatus = 0; |
|
17 |
+int motorSpeed = 100; |
|
18 |
+int gotoTilt = 70; |
|
19 |
+ |
|
20 |
+ |
|
21 |
+int val; |
|
22 |
+int valOld; |
|
23 |
+char buf[12]; |
|
24 |
+char buf2[12]; |
|
25 |
+ |
|
16 | 26 |
// Update these with values suitable for your network. |
17 | 27 |
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; |
18 | 28 |
IPAddress ip(10, 13, 37, 165); |
... | ... |
@@ -48,7 +58,7 @@ void setup() |
48 | 58 |
pinMode(posTilt, INPUT); |
49 | 59 |
pinMode(posPan, INPUT); |
50 | 60 |
|
51 |
- Serial.begin(9600); |
|
61 |
+ Serial.begin(115200); |
|
52 | 62 |
Ethernet.begin(mac, ip); |
53 | 63 |
client.setBufferSize(255); |
54 | 64 |
|
... | ... |
@@ -85,8 +95,22 @@ void loop() |
85 | 95 |
reconnect(); |
86 | 96 |
} |
87 | 97 |
client.loop(); |
88 |
- |
|
89 |
- |
|
98 |
+val = analogRead(posTilt); |
|
99 |
+//Serial.println(val); |
|
100 |
+val = map(val, 0, 902, 0, 90); |
|
101 |
+if (((val - valOld) > 1) || ((valOld - val) > 1)) { |
|
102 |
+ if(speedStatus == 0) { |
|
103 |
+ motorSpeed = map(abs((val - gotoTilt)), 5, 20, 30, 100); |
|
104 |
+ if (motorSpeed < 30) { motorSpeed = 30; } |
|
105 |
+ if (motorSpeed > 100) { motorSpeed = 100; } |
|
106 |
+ client.publish("hamradio/rotator/motor/speed", itoa(motorSpeed, buf2, 10)); |
|
107 |
+ } |
|
108 |
+ valOld = val; |
|
109 |
+ client.publish("hamradio/rotator/pos/tilt", itoa(val, buf, 10)); |
|
110 |
+ delay(15); |
|
111 |
+ Serial.println(analogRead(posTilt)); |
|
112 |
+} |
|
113 |
+delay(15); |
|
90 | 114 |
|
91 | 115 |
|
92 | 116 |
} |