-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
79 lines (71 loc) · 1.62 KB
/
main.cpp
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
#include <Arduino.h>
const int inputPin2 = 27;
const int inputPin = 12;
const int outputPin = 14;
const int readingsPerSecond = 250;
const int interval = 1000 / readingsPerSecond;
unsigned long previousMillis = 0;
void setup()
{
Serial.begin(115200);
pinMode(inputPin, INPUT);
pinMode(inputPin2, INPUT);
pinMode(outputPin, OUTPUT);
}
void printSource()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
Serial.print(currentMillis);
Serial.print(", ");
Serial.print(analogRead(inputPin));
Serial.print(", ");
Serial.println(analogRead(inputPin2));
}
}
void printOut()
{
analogWrite(outputPin, map(3000, 0, 4095, 0, 255));
while (true)
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
Serial.print(currentMillis);
Serial.print(", ");
Serial.print(analogRead(inputPin));
Serial.print(", ");
Serial.println(analogRead(inputPin2));
}
}
}
void ramp()
{
for (int i = 0; i < 250; i++)
{
analogWrite(outputPin, i);
delay(10);
Serial.print(map(i, 0, 255, 0, 4095));
Serial.print(", ");
Serial.print(analogRead(inputPin));
Serial.print(", ");
Serial.println(analogRead(inputPin2));
}
for (int i = 255; i > 0; i--)
{
analogWrite(outputPin, i);
delay(10);
Serial.print(map(i, 0, 255, 0, 4095));
Serial.print(", ");
Serial.print(analogRead(inputPin));
Serial.print(", ");
Serial.println(analogRead(inputPin2));
}
}
void loop()
{
printOut();
}