The below code is the "higher level" variant and calls some external codes.
Expand|Select|Wrap|Line Numbers
- void loop() {
- potValue = analogRead(potPin);
- int servoPulse = map(potValue, 0, 1023, 600, 1500); //Maps pulse in microseconds
- servo.writeMicroseconds(servoPulse);
- //int valveDegrees = servo.read(); //Reads the degrees the air manifold valve is open
- pressureValue = analogRead(pressurePin);
- int MAP = map(pressureValue, 40.92, 1002.54, 20, 250); //Maps pressure in kPa
- tempValue = analogRead(tempPin);
- int MAT = map(tempValue, 0, 1023, 0, 500); //Maps temp in K- values require confirmation
- //
- pulseDelay = 1000*(((.79*2*14.01+.21*2*16)*7920*.148*.6)/(.0821*14.9*101.325*20))*(MAP/MAT);
- sparkDelay = 215.94214021463*(timeNew-timeOld)-pulseDelay+corr; //Delay before spark fires (should the pulse calculations be at the beginning or end?)
- }
Expand|Select|Wrap|Line Numbers
- void loop() {
- pressureValue = analogRead(A2);
- int MAP = (pressureValue-40.92)*(230/961.62)+20;
- tempValue = analogRead(A4);
- int MAT = tempValue*(500/1023); //Maps temp in K- values require confirmation
- potValue = analogRead(A0);
- int servoPulse = potValue*(900/1023)+600; //Maps pulse in microseconds
- //
- pulseDelay = ((28.85*7920*148*.6)/(.0821*15*101.325*20))*(MAP/MAT); //Stoichiometric calculation for fuel injection timing- requires C, D, and F- simplify the number once found (allow for lean mix)
- sparkDelay = 215.94214021463*(timeNew-timeOld)-pulseDelay+corr; //Delay before spark fires (should the pulse calculations be at the beginning or end?)
- if (servoTimer<=(millis()-20)) {
- PORTB=B00000001;
- delayMicroseconds(servoPulse);
- PORTB=B00000000;
- servoTimer=millis();
- }
- }
-Hari Ganti