-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwideband.c
45 lines (31 loc) · 987 Bytes
/
wideband.c
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
#include "U8glib.h"
#define OLED_RESET 4
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); // I2C / TWI
void setup() {
// screen is mounted upside down. 180 rotation is needed to display correctly
u8g.setRot180();
Serial.begin(9600);
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// convert voltage to a value mirroring AFR data displayed on the AEM gauge
float AFR = (voltage * 2.375) + 7.3125;
// print the AFR value on serial monitor
Serial.println(AFR);
// draw the value on the OLED screen
u8g.firstPage();
do
{
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(36, 10);
u8g.print("AIR/FUEL");
u8g.setPrintPos(36, 30);
u8g.print(AFR);
}
while ( u8g.nextPage() );
// delay added to slow readings displayed. didn't work
//delay(100);
}