-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleDyno_New-Delay_Nano
66 lines (59 loc) · 1.74 KB
/
SimpleDyno_New-Delay_Nano
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
const int NumPortsToRead = 6;
int AnalogResult[NumPortsToRead];
volatile unsigned long TimeStamp = 0;
volatile unsigned long time1 = 0;
volatile unsigned long time2 = 0;
volatile unsigned long Oldtime1 = 0;
volatile unsigned long Oldtime2 = 0;
volatile unsigned long TempTime1 = 0;
volatile unsigned long TempTime2 = 0;
String AllResult = "";
#define UPDATE_INTERVAL 10 // Number of milliseconds between each update
unsigned long lastUpdateTime;
void setup()
{
// Initialize serial communication
// Ensure that Baud rate specified here matches that selected in SimpleDyno
// Availailable Baud rates are:
// 9600, 14400, 19200, 28800, 38400, 57600, 115200
Serial.begin(115200);
// Initialize interupts (Pin2 is interrupt 0 = RPM1, Pin3 in interrupt 1 = RPM2)
attachInterrupt(0,channel1,FALLING);
// attachInterrupt(1,channel2,FALLING);
lastUpdateTime = millis();
}
void loop()
{
unsigned long currentTime = millis();
if((currentTime - lastUpdateTime) > UPDATE_INTERVAL)
{
lastUpdateTime = currentTime;
AllResult = "";
AllResult += micros();
AllResult += ",";
AllResult += TempTime1;
AllResult += ",";
AllResult += time1;
AllResult += ",";
AllResult += TempTime2;
AllResult += ",";
AllResult += time2;
for (int Looper = 0; Looper < NumPortsToRead;Looper++)
{
AnalogResult[Looper] = analogRead(Looper);
AllResult += ",";
AllResult += AnalogResult[Looper];
}
Serial.println (AllResult);
Serial.flush();
//delay(20); //20 is default
}
}
//////////////////////////////////////////////////////////////
//Interrupt routine for RPM1
void channel1()
{
TempTime1 = micros();
time1 = TempTime1-Oldtime1;
Oldtime1 = TempTime1;
}