-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharduino_firmware.ino
More file actions
82 lines (79 loc) · 1.78 KB
/
Copy patharduino_firmware.ino
File metadata and controls
82 lines (79 loc) · 1.78 KB
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
String Comm;
int output = DAC0;
int input;
int val;
String inData;
String tempValue;
String channel;
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue;
bool isData = false;
int i = 0;
int ledPin = 53;
void setup() {
Serial.begin(9600);
while (!Serial);
analogWriteResolution(12);
analogWrite(DAC0, 0);
analogWrite(DAC1, 0);
pinMode(ledPin, OUTPUT);
}
void loop() {
while (Serial.available() > 0 ) {
char value = Serial.read();
Comm += value;
if (value == '\n') {
isData = true;
}
}
if (isData) {
isData = false;
if (Comm.startsWith("IDN")) {
Serial.print("General DAQ Device built by Uetke. v.1.2019");
Serial.print("\n");
}
else if (Comm.startsWith("OUT")) {
channel = Comm[6];
if (channel.toInt() == 1) {
output = DAC1;
}
else if (channel.toInt() == 0) {
output = DAC0;
}
tempValue = "";
for (i = 8; i < Comm.length(); i++) {
tempValue += Comm[i];
}
val = tempValue.toInt();
analogWrite(output, val);
Serial.print(tempValue);
}
else if (Comm.startsWith("IN")) {
channel = Comm[5];
input = channel.toInt();
val = analogRead(input);
Serial.print(val);
Serial.print("\n");
}
else if (Comm.startsWith("DI")){
Serial.println("Digital");
channel = Comm[3]+Comm[4];
tempValue = Comm[6];
if (tempValue.toInt() == 0){
digitalWrite(ledPin, LOW);
Serial.println("OFF");
Serial.println(ledPin);
}
else{
digitalWrite(ledPin, HIGH);
Serial.println("ON");
Serial.println(channel.toInt());
}
}
else {
Serial.print("Command not known\n");
}
Comm = "";
}
delay(20);
}