JDM Map Sensor and Gauge
#19
Evolved Member
iTrader: (2)
Join Date: Oct 2003
Location: norcal / socal
Posts: 512
Likes: 0
Received 0 Likes
on
0 Posts
here is my code for the lcd gauge. The boost formula is calibrated to the JDM map sensor.
mind you i am not a full time coder.
//budlong
//2008
////remove warning flags from boost and afr routines.. make own if statement at void setup level that say if over, switch to....
///turn off cursor on display
int thePinval = 0; // variable for reading the button's pin status
int val = 0; // variable to store the value coming from the sensor
int psi = 0; //raw adc data
int psiR = 0;
int psiR2 = 0;
int psiR3 = 0;
int psiR2MAX = 0;
int psiMAX = 0; //max psi does not register negative
int afr =0;
unsigned int afrR = 0;
unsigned int afrR2 = 0;
int Warn_lo = 22; //warning low trigger SET TO 21 before completion
int Warn_hi = 24; //warning high trigger SET TO 24 before completion
int warning;
int calcpressure;
int addOneDisplay =0;
long time;
int boostInput=1;
int afrInput = 5;
int buttonA = 8;
int buttonB = 7;
int analogBoost = 3;
int analogAfr = 6;
void setup() {
pinMode(buttonA, INPUT); // declare button A input 7
pinMode(buttonB, INPUT); // declare button B input 8
pinMode(analogBoost,OUTPUT); ///5v signal simulates BOOST
analogWrite(analogBoost,255); //write full 5v signal to pin 3
pinMode(analogAfr,OUTPUT); ///5v signal simulates AFR
analogWrite(analogAfr,255); //write full 5v signal to pin 5
Serial.begin(9600);
delay (200);
Serial.print(254,BYTE);
Serial.print(1,BYTE);
delay (500);
}
void loop(){
////FORMULAS///
psi = (((0.333 * analogRead(boostInput)) * 14.5)/100)-15.08; ////.333 * ADC value * 14.5 * atmospheric pressure sensor reads from -15 to +34.~~
//////remander still not working correctly
psiR = psi *100 ;
psiR2 =100 *((((0.333 * analogRead(boostInput)) * 14.5)/100)-15.08);
psiR3 = (psiR2 -psiR);
if (psiR3 < 0) psiR3=0;
afr =analogRead(afrInput)/50; ///calculate afr 5v times 10 to move decimal over one space turning 3 int 30???
Peak_val();
/////main routines////////////--------------------------------------------------------------------------------------------------------------------------------
if (psi >= Warn_lo){
Warn();
}
else {
PeakReset();
ChangeDisplay();
}
}
//------------------Routines-------------------------////
///////////////////Display////////////////////////////////////
int clearScreen(){
Serial.print(254,BYTE);
Serial.print(1,BYTE);
delay (100);
}
int topScreen(){
Serial.print(254,BYTE);
Serial.print(128,BYTE);
//delay (100);
}
int botScreen(){
Serial.print(254,BYTE);
Serial.print(192,BYTE);
//delay (100);
}
///////////////////Buttons////////////////////////////////////
int PeakReset(){
thePinval = digitalRead(buttonA); // read input value of buttton A
if (thePinval == LOW) { // check if the input is LOW (button pressed)
/////clear screen and reset peak value
clearScreen();
psiMAX=0;
psiR2MAX=0;
}
}
int ChangeDisplay(){
thePinval = digitalRead(buttonB);
if (addOneDisplay==0){
Boost_dis();
Peak_dis();
if (thePinval == LOW){
addOneDisplay=1;
clearScreen();
delay (500);
}
}
else if (addOneDisplay==1){
Boost_dis();
Boost_graph();
if (thePinval == LOW){
addOneDisplay=2;
clearScreen();
delay (500);
}
}
else if (addOneDisplay==2){
Afr_dis();
Afr_graph();
if (thePinval == LOW){
addOneDisplay=0;
clearScreen();
delay (500);
} ////add more else ifs to have more display selection combinations
}
}
///////////////////Displays////////////////////////////////////
int Boost_dis(){ //after decimal not complete
topScreen();
Serial.print(" psi: ");
Serial.print( psi), BYTE;
Serial.print(".");
Serial.println(psiR3),DEC;
}
int Afr_dis(){ //after decimal not complete
topScreen();
Serial.print(" afr: ");
Serial.print( afr), BYTE;
Serial.print(".");
Serial.println(afrR2),BYTE;
}
int Peak_dis(){
botScreen();
Serial.print(" peak: ");
Serial.print( psiMAX), DEC;
Serial.print(".");
Serial.println(psiR2MAX),DEC;
}
///////////////////Graphs////////////////////////////////////
int Boost_graph(){
int xb;
int xa = psi /2.5;
int xbar;
int c=0;
botScreen();
for( xb = 0;xb <xa;xb++){
Serial.print(5,BYTE); /////character to display as bar in graph
delay (10);
c=c+1;
}
if(c <xa) {
botScreen();
Serial.print(" ");
delay (10);
}
}
int Afr_graph(){//try to add your own characters
int afrCursor;
afrCursor=analogRead(5) *12 / 1020; //divided analog in 5 by 14 slots to fill on the graph to get the cursor position
botScreen();
Serial.print("[ ]");
Serial.print(254, BYTE);
if (afrCursor >8) afrCursor =8; ///keep cursor from moving to far to the right
if (afrCursor <1) afrCursor =0;
Serial.print(194 + afrCursor, BYTE);
if (afr < 12) Serial.print("lean");
else if (afrCursor > 15) Serial.print("rich");
else Serial.print("opti");
delay (100);
}
///////////////////Various////////////////////////////////////
int Peak_val(){
if (psiR2MAX < psiR3 && psiMAX==psi){
psiR2MAX = psiR3;
}
if (psiMAX <psi){
psiMAX = psi;
psiR2MAX = psiR3;
}
}
int Warn(){
if (psi >= Warn_lo && psi < Warn_hi){ //warning triggerd
botScreen();
Serial.print("!!! WARNING !!! ");
delay(300);
botScreen();
Serial.print(" ");
}
if (psi >= Warn_hi){ //OVERBOOST warning triggered
topScreen();
delay (300);
Serial.print("!!! WARNING !!! ");
botScreen();
Serial.print("+ + + B O O S T");
delay (200);
clearScreen();
Serial.print(" ");
botScreen();
Serial.print(" ");
}
}
//// AFR scale... 14.5 cruising 11.5 redline .... scale should read from 8afr to 18afr
mind you i am not a full time coder.
//budlong
//2008
////remove warning flags from boost and afr routines.. make own if statement at void setup level that say if over, switch to....
///turn off cursor on display
int thePinval = 0; // variable for reading the button's pin status
int val = 0; // variable to store the value coming from the sensor
int psi = 0; //raw adc data
int psiR = 0;
int psiR2 = 0;
int psiR3 = 0;
int psiR2MAX = 0;
int psiMAX = 0; //max psi does not register negative
int afr =0;
unsigned int afrR = 0;
unsigned int afrR2 = 0;
int Warn_lo = 22; //warning low trigger SET TO 21 before completion
int Warn_hi = 24; //warning high trigger SET TO 24 before completion
int warning;
int calcpressure;
int addOneDisplay =0;
long time;
int boostInput=1;
int afrInput = 5;
int buttonA = 8;
int buttonB = 7;
int analogBoost = 3;
int analogAfr = 6;
void setup() {
pinMode(buttonA, INPUT); // declare button A input 7
pinMode(buttonB, INPUT); // declare button B input 8
pinMode(analogBoost,OUTPUT); ///5v signal simulates BOOST
analogWrite(analogBoost,255); //write full 5v signal to pin 3
pinMode(analogAfr,OUTPUT); ///5v signal simulates AFR
analogWrite(analogAfr,255); //write full 5v signal to pin 5
Serial.begin(9600);
delay (200);
Serial.print(254,BYTE);
Serial.print(1,BYTE);
delay (500);
}
void loop(){
////FORMULAS///
psi = (((0.333 * analogRead(boostInput)) * 14.5)/100)-15.08; ////.333 * ADC value * 14.5 * atmospheric pressure sensor reads from -15 to +34.~~
//////remander still not working correctly
psiR = psi *100 ;
psiR2 =100 *((((0.333 * analogRead(boostInput)) * 14.5)/100)-15.08);
psiR3 = (psiR2 -psiR);
if (psiR3 < 0) psiR3=0;
afr =analogRead(afrInput)/50; ///calculate afr 5v times 10 to move decimal over one space turning 3 int 30???
Peak_val();
/////main routines////////////--------------------------------------------------------------------------------------------------------------------------------
if (psi >= Warn_lo){
Warn();
}
else {
PeakReset();
ChangeDisplay();
}
}
//------------------Routines-------------------------////
///////////////////Display////////////////////////////////////
int clearScreen(){
Serial.print(254,BYTE);
Serial.print(1,BYTE);
delay (100);
}
int topScreen(){
Serial.print(254,BYTE);
Serial.print(128,BYTE);
//delay (100);
}
int botScreen(){
Serial.print(254,BYTE);
Serial.print(192,BYTE);
//delay (100);
}
///////////////////Buttons////////////////////////////////////
int PeakReset(){
thePinval = digitalRead(buttonA); // read input value of buttton A
if (thePinval == LOW) { // check if the input is LOW (button pressed)
/////clear screen and reset peak value
clearScreen();
psiMAX=0;
psiR2MAX=0;
}
}
int ChangeDisplay(){
thePinval = digitalRead(buttonB);
if (addOneDisplay==0){
Boost_dis();
Peak_dis();
if (thePinval == LOW){
addOneDisplay=1;
clearScreen();
delay (500);
}
}
else if (addOneDisplay==1){
Boost_dis();
Boost_graph();
if (thePinval == LOW){
addOneDisplay=2;
clearScreen();
delay (500);
}
}
else if (addOneDisplay==2){
Afr_dis();
Afr_graph();
if (thePinval == LOW){
addOneDisplay=0;
clearScreen();
delay (500);
} ////add more else ifs to have more display selection combinations
}
}
///////////////////Displays////////////////////////////////////
int Boost_dis(){ //after decimal not complete
topScreen();
Serial.print(" psi: ");
Serial.print( psi), BYTE;
Serial.print(".");
Serial.println(psiR3),DEC;
}
int Afr_dis(){ //after decimal not complete
topScreen();
Serial.print(" afr: ");
Serial.print( afr), BYTE;
Serial.print(".");
Serial.println(afrR2),BYTE;
}
int Peak_dis(){
botScreen();
Serial.print(" peak: ");
Serial.print( psiMAX), DEC;
Serial.print(".");
Serial.println(psiR2MAX),DEC;
}
///////////////////Graphs////////////////////////////////////
int Boost_graph(){
int xb;
int xa = psi /2.5;
int xbar;
int c=0;
botScreen();
for( xb = 0;xb <xa;xb++){
Serial.print(5,BYTE); /////character to display as bar in graph
delay (10);
c=c+1;
}
if(c <xa) {
botScreen();
Serial.print(" ");
delay (10);
}
}
int Afr_graph(){//try to add your own characters
int afrCursor;
afrCursor=analogRead(5) *12 / 1020; //divided analog in 5 by 14 slots to fill on the graph to get the cursor position
botScreen();
Serial.print("[ ]");
Serial.print(254, BYTE);
if (afrCursor >8) afrCursor =8; ///keep cursor from moving to far to the right
if (afrCursor <1) afrCursor =0;
Serial.print(194 + afrCursor, BYTE);
if (afr < 12) Serial.print("lean");
else if (afrCursor > 15) Serial.print("rich");
else Serial.print("opti");
delay (100);
}
///////////////////Various////////////////////////////////////
int Peak_val(){
if (psiR2MAX < psiR3 && psiMAX==psi){
psiR2MAX = psiR3;
}
if (psiMAX <psi){
psiMAX = psi;
psiR2MAX = psiR3;
}
}
int Warn(){
if (psi >= Warn_lo && psi < Warn_hi){ //warning triggerd
botScreen();
Serial.print("!!! WARNING !!! ");
delay(300);
botScreen();
Serial.print(" ");
}
if (psi >= Warn_hi){ //OVERBOOST warning triggered
topScreen();
delay (300);
Serial.print("!!! WARNING !!! ");
botScreen();
Serial.print("+ + + B O O S T");
delay (200);
clearScreen();
Serial.print(" ");
botScreen();
Serial.print(" ");
}
}
//// AFR scale... 14.5 cruising 11.5 redline .... scale should read from 8afr to 18afr
Thread
Thread Starter
Forum
Replies
Last Post
-Evo Aaron-
Evo Show / Shine
30
Apr 19, 2010 01:21 AM
Bster13
Evo Engine / Turbo / Drivetrain
14
Dec 10, 2008 11:10 PM
Obsoleteasian
Lancer Audio and Security (All models)
7
Sep 26, 2002 05:42 AM