
/*
Analog input, analog output, serial output
http://www.arduino.cc/en/Tutorial/AnalogInOutSerial
*/
// These constants won't change. They're used to give names to the pins used:
const int Poterbo = A0; // Analog input pin that the potentiometer is attached to
const int Poairflow = A1;
const int Pofuelpre = A2;
const int sensorTerbo = A8;
const int sensorAirflow = A9;
const int sensorFuelpre = A10;
const int Outterbo = 9; // Analog output pin that the LED is attached to
const int OutAirflow = 10;
const int OutFuelpre = 11;
int sensorValue1 = 0; // value read from the pot
int sensorValue2 = 0;
int sensorValue3 = 0;
int sensorValue4 = 0;
int sensorValue5 = 0;
int sensorValue6 = 0;
int terboValue = 0; // value output to the PWM (analog out)
int AirflowValue = 0;
int FuelValue = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(115200);
}
void loop() {
// read the analog in value:
sensorValue1 = analogRead(Poterbo);
sensorValue2 = analogRead(Poairflow);
sensorValue3 = analogRead(sensorTerbo);
sensorValue4 = analogRead(sensorAirflow);
sensorValue5 = analogRead(Pofuelpre);
sensorValue6 = analogRead(sensorFuelpre);
float ganterbo = ((sensorValue1 - 511)*1.6) + sensorValue3;// 1.2 , 1.4
float ganairfl = ((sensorValue2 - 511)*1.6) + sensorValue4;
float ganFuel = sensorValue6 - (sensorValue5*0.6);//0.8 , 0.5
int kanterboinf = constrain(ganterbo, 0, 1023);
int kanairflinf = constrain(ganairfl, 0, 1023);
int kanFuelinf = constrain(ganFuel, 0, 1023);
// map it to the range of the analog out:
terboValue = map(kanterboinf, 0, 1023, 0, 255);
AirflowValue = map(kanairflinf, 0, 1023, 0, 255);
FuelValue = map(kanFuelinf, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(Outterbo, terboValue); //low pass filter r = 10k , c = 1 uF
analogWrite(OutAirflow, AirflowValue); //low pass filter r = 4.7k , c = 100 uF
analogWrite(OutFuelpre, FuelValue);//low pass filter r = 10k , c = 1 uF
// print the results to the Serial Monitor:
Serial.print("sensor = ");
Serial.print(sensorValue1);
Serial.print("sensor = ");
Serial.print(sensorValue2);
Serial.print("sensor = ");
Serial.print(terboValue*5/255.0,2);
Serial.print("\t air = ");
Serial.println(AirflowValue*5/255.0,2);//
// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(10);
}