-
Notifications
You must be signed in to change notification settings - Fork 3
/
mksmfc.ino
46 lines (42 loc) · 984 Bytes
/
mksmfc.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
#define LED_PIN LED_BUILTIN
#define TRIG_PIN 27
#define ADC_PIN 26
#define SETPOINT_PIN 25
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(SETPOINT_PIN, OUTPUT);
pinMode(ADC_PIN, INPUT);
analogReadResolution(12);
analogWriteResolution(16);
digitalWrite(LED_PIN, LOW);
analogWrite(LED_PIN, 0);
}
void loop() {
if (Serial.available() > 0) {
char cmd = Serial.read();
switch (cmd) {
case 's':
{
int voltage = Serial.parseInt();
if (voltage > 0) {
digitalWrite(TRIG_PIN, HIGH);
} else {
digitalWrite(TRIG_PIN, LOW);
}
analogWrite(LED_PIN, voltage);
Serial.printf("oks%d\n", voltage);
}
return;
case 'r':
{
Serial.println(float(analogRead(ADC_PIN)) / 100);
}
return;
default:
Serial.println("Unknown command");
return;
}
}
}