Skip to content

Instantly share code, notes, and snippets.

@JohnPersano
Created December 16, 2015 05:13
Show Gist options
  • Save JohnPersano/dc17d879e15392fc8931 to your computer and use it in GitHub Desktop.
Save JohnPersano/dc17d879e15392fc8931 to your computer and use it in GitHub Desktop.
Group 3 Application Sketch
#include <LiquidCrystal.h>
#include<stdlib.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
float mpgs[10];
int counter = 0;
const int numReadings = 10;
float readings[numReadings];
int readIndex = 0;
float total = 0;
float average = 0;
int inputPin = A0;
void setup() {
lcd.begin(16, 2);
lcd.print("Group 3");
lcd.setCursor(0, 1);
lcd.print("MPG calculator");
delay(5000);
int i;
for (i = 0; i < 16; i++) {
lcd.scrollDisplayRight();
delay(150);
}
lcd.clear();
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("1998 Honda Civic");
total = total - readings[readIndex];
float val = analogRead(0);
// Bring it into a typical RPM rate
val /= 1023;
val *= 7500;
// 1998 Honda Accord approximate gph per rpm (1gph to 2833 rpms)
val += 2833;
float mpg = 55 / (val / 2833);
readings[readIndex] = mpg;
total = total + readings[readIndex];
readIndex++;
if (readIndex >= numReadings) {
readIndex = 0;
}
average = total / numReadings;
lcd.setCursor(0, 1);
lcd.print(average);
lcd.setCursor(5, 1);
lcd.print("MPG @ 55MPH");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment