-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimInterfaceHDGv2.ino
195 lines (172 loc) · 4.57 KB
/
SimInterfaceHDGv2.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//Sample using LiquidCrystal library
//#include <LiquidCrystal.h>
#include <TimerOne.h>
#include <ClickEncoder.h>
//#include <Encoder.h>
/*******************************************************
This program will test the LCD panel and the buttons
Mark Bramwell, July 2010
********************************************************/
// select the pins used on the LCD panel
//LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//Encoder enc(A0,A1);
ClickEncoder *encoder;
bool led_state=HIGH;
//int pins[3][4]={{0,1,2,3},{4,5,6,7},{8,9,10,11}};
int pins[4]={2,3,4,5};
int bit_id[3]={6,7,8};
float dis_value=888;
const int led_pin=9;
const int btn=10;
const int en_btn=11;
const int bi=12;
const int lt=13;
float vs=0;
int hdg_sel=0;
int alt_sel=0;
int spd_sel=0;
int counter = 0;
int currentStateCLK;
int previousStateCLK;
int16_t last, value;
void timerIsr() {
encoder->service();
}
void getDataFromFS2020(void);
void toggle_led(void)
{
if(led_state==LOW)
{
led_state=HIGH;
digitalWrite(led_pin, led_state);
}
else
{
led_state=LOW;
analogWrite(led_pin, 100);
}
}
void set_led(void)
{
analogWrite(led_pin, 100);
}
void set_led_state(void)
{
digitalWrite(led_pin, led_state);
}
void set_dis_single(int _id, int _value)
{
digitalWrite(bit_id[_id], LOW);
for(int i=0;i<4;i++)
{
bool state=bitRead(_value, i);
digitalWrite(pins[i],state);
}
delay(20);
digitalWrite(bit_id[_id], HIGH);
}
void set_dis(int _value)
{
int value1[3]={0,0,0};
value1[2]=_value/100;
value1[1]=(_value-value1[2]*100)/10;
value1[0]=_value-value1[2]*100-value1[1]*10;
for(int i=0;i<3;i++)
{
set_dis_single(i,value1[i]);
}
}
void setup()
{
Serial.begin(9600);
encoder = new ClickEncoder(A0, A1, 11);
Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);
last = -1;
pinMode(led_pin, OUTPUT);
pinMode(bi, OUTPUT);
for(int i=2;i<10;i++)
{
pinMode(i, OUTPUT);
}
pinMode(btn, INPUT_PULLUP);
pinMode(en_btn, INPUT_PULLUP);
pinMode(lt, INPUT);
// set_dis(dis_value);
digitalWrite(led_pin, led_state);
digitalWrite(bi, HIGH);
}
long oldPosition = -999;
int dis_value_old=0;
void loop()
{
value = encoder->getValue();
// long newPosition = enc.read();
// if (newPosition != oldPosition) {
// long poserr=newPosition-oldPosition;
// oldPosition = newPosition;
dis_value+=float(value)/2;
// Serial.println(dis_value);
// Serial.println(newPosition);
// }
// getDataFromFS2020();
if(digitalRead(lt)==LOW)
{
set_led();
}
else
{
set_led_state();
}
if(digitalRead(en_btn)==LOW)
{
dis_value=0;
}
if(digitalRead(btn)==LOW)
{
toggle_led();
delay(200);
}
dis_value=max(min(dis_value,999),0);
if(dis_value != dis_value_old)
{
set_dis(int(dis_value));
}
dis_value_old=dis_value;
}
void getDataFromFS2020() {
//Declaration of variables to store the incoming data
String input = "@"; //General input buffer
int value; //Value memory
int index; //Index memory
if (Serial.available() > 0) {
Serial.readStringUntil('@'); //Look out for first Indicator
input += Serial.readStringUntil('/') + "/"; //read the ID
index = Serial.readStringUntil('=').toInt();
if (input.indexOf("@763/") != -1) { //Check for Vertical Speed ID
vs = Serial.readStringUntil('$').toInt(); //Saves the value as int to "value" Variable for later use
//Do something with the values...
//like displaying or sending something
//Or include a function like:
//void refreshStepperMotorPosition(int value)
}
if (input.indexOf("@86/") != -1) { //Check for Vertical Speed ID
hdg_sel = Serial.readStringUntil('$').toInt(); //Saves the value as int to "value" Variable for later use
//Do something with the values...
//like displaying or sending something
//Or include a function like:
//void refreshStepperMotorPosition(int value)
}
// if (input.indexOf("@90/") != -1) { //Check for AP Master ID -> Gives Bool Value
// value = Serial.readStringUntil('$').toInt(); //Saves the value as int to "value" Variable for later use
//
// if (value == 1) {
// //do something
// Serial.print("@465/1$"); //Turns landing lights on when AP is on
// } else {
// //do something else
// Serial.print("@465/0$"); //Turns landing lights on when AP is off
// }
// }
}
}