-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradio-simulator.ino
69 lines (49 loc) · 1.4 KB
/
radio-simulator.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
#define PULSE_PIN 8 // Pin for synchronising communication
#define SYNC_DELAY 64 // Delay (us) for synchronizing pulse
// Pins to use for parallel communication
const int inputPins[] = {
0, 1, 2, 3, 4, 5, 6, 7
};
// Buffer for input values
const int inputPinCount = sizeof(inputPins) / sizeof(int);
int inputValues[inputPinCount];
// Simulate NAROM rocket radio
// Set synchronising pin high, wait 64 ms, set low, wait 64 ms
void sendPulseAndWait() {
Serial.println("Sending pulse!");
digitalWrite(PULSE_PIN, HIGH);
delayMicroseconds(SYNC_DELAY);
digitalWrite(PULSE_PIN, LOW);
delayMicroseconds(SYNC_DELAY);
}
// Read values from parallel pins
void readValues() {
Serial.println("Reading values...");
for (int i = 0; i < inputPinCount; i++) {
inputValues[i] = digitalRead(i);
}
}
// Print values from parallel pins
void printValues() {
Serial.print("Values: ");
for (int i = 0; i < inputPinCount; i++) {
Serial.print(inputValues[i]);
}
Serial.println();
}
void setup() {
Serial.begin(9600);
// Set up input pins
for (int i = 0; i < inputPinCount; i++) {
pinMode(inputPins[i], INPUT);
}
// Set up pulse pin
pinMode(PULSE_PIN, OUTPUT);
// Set pulse pin low
digitalWrite(PULSE_PIN, LOW);
}
void loop() {
sendPulseAndWait();
readValues();
printValues();
}