Statistics: Posted by stefanst — Sun May 14, 2017 11:45 pm
Statistics: Posted by stefanst — Sun May 14, 2017 10:40 am
Statistics: Posted by puff — Sun May 14, 2017 7:24 am
Code:
// These constants won't change. They're used to give names// to the pins used:const int oilIn = A0; // Analog input pin that the potentiometer is attached toconst int oilOut = 11; // Analog output pin that the transistor is attached toconst int waterIn = A1; // Analog input pin that the potentiometer is attached toconst int waterOut = 10; // Analog output pin that the transistor is attached to/*const float xOffsetOil = 20;const float xStepOil = 50;const float yValueOil [] = { 20.0, 40.0, 60.0, 80.0, 100.0, 120.0, 140.0, 160.0, 180.0, 200.0, 220.0}; const float yPressOil [] = { 96.1, 82.9, 69.6, 56.4, 44.2, 32.6, 22.8, 15.4, 9.3, 3.7, -1.1};*/const float xOffsetOil = 100;const float xStepOil = 50;const float yValueOil [] = { 125, 128, 131, 135, 139, 144, 150, 157, 170, 189, 203, 238 };const float yPressOil [] = { 0, 3, 7, 11, 16, 22, 29, 37, 47, 59, 74, 92 };const float xOffsetWater = 60;const float xStepWater = 30;const float yValueWater [] = { -60, 10, 60, 92, 133, 146, 157, 165, 171, 176, 180, 183, 186, 189, 192, 195, 198, 201, 205, 209, 214, 219, 224, 230, 236, 243, 250, 255, 255, 255, 255, 255, 255 };const float yTempWater [] = { 310, 285, 264, 249, 237, 226, 216, 207, 199, 192, 186, 180, 175, 170, 165, 160, 155, 150, 145, 140, 135, 130, 124, 118, 112, 106, 98, 89, 78, 67, 55, 43, 31 };void setup() { pinMode (oilIn, INPUT); pinMode (waterIn, INPUT); pinMode (oilOut, OUTPUT); pinMode (waterOut, OUTPUT); // initialize serial communications at 9600 bps: Serial.begin(9600); Serial.println ("Ready");}int lookup (float val, float lowX, float highX, float lowY, float highY) { float retFloat = (highY - lowY)/(highX-lowX) * val + lowY + 0.5; int retInt = retFloat; return retInt;}void loop() { // read the analog in value: int sensorRawWater = 0 ; int sensorRawOil = 0 ; for ( int i=0; i<10; i++) { sensorRawWater = sensorRawWater + analogRead(waterIn); sensorRawOil = sensorRawOil + analogRead(oilIn); /* Serial.println(sensorRawWater); Serial.println(sensorRawOil); delay (500);*/ } float sensorRawWaterAvg = sensorRawWater / 10; float sensorRawOilAvg = sensorRawOil / 10; float sensorValueWater = sensorRawWaterAvg-xOffsetWater; int xIntWater = sensorValueWater / xStepWater; int outputValueWater = lookup(sensorValueWater - (xIntWater * xStepWater) , 0, xStepWater, yValueWater [xIntWater], yValueWater [xIntWater+1]); int outputTempWater = lookup(sensorValueWater - (xIntWater * xStepWater) , 0, xStepWater, yTempWater [xIntWater], yTempWater [xIntWater+1]); float sensorValueOil = sensorRawOilAvg-xOffsetOil; int xIntOil = sensorValueOil / xStepOil; int outputValueOil = lookup(sensorValueOil - (xIntOil * xStepOil) , 0, xStepOil, yValueOil [xIntOil], yValueOil [xIntOil+1]); int outputPressOil = lookup(sensorValueOil - (xIntOil * xStepOil) , 0, xStepOil, yPressOil [xIntOil], yPressOil [xIntOil+1]); if (outputValueWater <0) { outputValueWater = 0; } if (outputValueWater > 255) { outputValueWater = 255; } analogWrite(waterOut, outputValueWater); if (outputValueOil <0) { outputValueOil = 0; } if (outputValueOil > 255) { outputValueOil = 255; } analogWrite(oilOut, outputValueOil); // print the results to the serial monitor: Serial.print("Water sensor raw = " ); Serial.print(sensorRawWaterAvg); // Serial.print("\t sensor-offset = " ); // Serial.print(sensorValueWater); Serial.print("\t xInt = "); Serial.print(xIntWater); Serial.print("\t output = "); Serial.print(outputValueWater); Serial.print("\t yTempWater [xIntWater+1] = "); Serial.print(yTempWater [xIntWater+1]); Serial.print("\t yTempWater [xIntWater] = "); Serial.print(yTempWater [xIntWater]); Serial.print("\t Temp = "); Serial.println(outputTempWater); // print the results to the serial monitor: Serial.print("Oil sensor raw = " ); Serial.print(sensorRawOilAvg); // Serial.print("\t sensor-offset = " ); // Serial.print(sensorValueOil); Serial.print("\t output = "); Serial.print(outputValueOil); Serial.print("\t Press = "); Serial.println(outputPressOil); // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(500); }
Statistics: Posted by stefanst — Sat May 13, 2017 11:04 pm
Statistics: Posted by stefanst — Sat May 13, 2017 10:58 pm
Statistics: Posted by puff — Sat May 13, 2017 8:40 pm
Statistics: Posted by puff — Sat May 13, 2017 1:25 pm
Statistics: Posted by puff — Sat May 13, 2017 10:17 am
Statistics: Posted by puff — Sat May 13, 2017 8:19 am
Statistics: Posted by stefanst — Sat May 13, 2017 2:49 am
Statistics: Posted by puff — Fri May 12, 2017 11:46 pm
Statistics: Posted by puff — Fri May 12, 2017 9:29 pm
Statistics: Posted by kb1gtt — Fri May 12, 2017 9:20 pm
Code:
/**+ * On single-coil or wasted spark setups you have to lower dwell at high RPM * offset 336 */ float sparkDwellRpmBins[DWELL_CURVE_SIZE];
Statistics: Posted by AndreyB — Fri May 12, 2017 8:28 pm