PHP код:
#include <MsTimer2.h>
//#include <DallasTemperature.h>
//DallasTemperature tempSensor;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
unsigned long time;
unsigned long taxometr = 0;
unsigned long dinaimpulsov = 0;
unsigned long ValSpCurr = 0;
int tmp37 = 0;
int kpa = 0;
int volts = 0;
int pboost = 0;
int atmos = 0;
int senstvaz =0;
int ds; // сенсор ds18b20
int val;
int mapp;
int peakrpm = 0;
int peakspeed = 0;
int taxo = 0;
int count = 0;
float peakboost = 0;
float boost, voltage;
byte bytes[8];
void setup()
{
lcd.begin(16, 2);
pinMode(2, INPUT);
pinMode(3, INPUT);
// * LOW когда на порту LOW
// * CHANGE , с LOW на HIGH и наоборот
// * RISING с LOW на HIGH
// * FALLING с HIGH на LOW
attachInterrupt(0, int_on, RISING);
//attachInterrupt(1, inton, FALLING);
MsTimer2::set(30000, flash); // таймер будет срабатывать через каждые 500ms
MsTimer2::start();//запустить таймер
//tempSensor.begin(10);
Serial.begin(115200);
}
void loop()
{
/////////////////ТАХОМЕТР///////////////////////////////////////
if (taxometr > 6000)
{
taxo = (80000000 / taxometr);
}
else
{
taxo = 0;
}
if (taxo > peakrpm) //pikrpm
{
peakrpm = taxo;
}
//////////////// СПИДОМЕТР//////////////////////////////////////
dinaimpulsov = pulseIn(3, HIGH, 100000); // Считывание длительности положительного импульса
ValSpCurr = (650000 / dinaimpulsov); // Перевод в км/ч
if (dinaimpulsov > 120000 || ValSpCurr > 350)
{
ValSpCurr = 0;
}
if (ValSpCurr > peakspeed) //pikspeed
{
peakspeed = ValSpCurr;
}
/////////////////////////////////////////////////////////////////
mapp = analogRead(2);//map-sensor
kpa = ((mapp*(0.0045)*(51.0)+16));// killopaskali
boost = ((mapp*(0.0045)*(51.0)+16)) / 100 -1; //kilopaskali v bar
atmos =map(mapp, 358, 384, 735, 780);// atmosfernoe davlenie
if (kpa > peakboost) //pikboost
{
peakboost = kpa;
pboost = peakboost;
}
voltage = 14.9 / 1024.0 * analogRead(1); // volts
volts = voltage * 10;
val = analogRead(0);// температура воды ваз
if (val >= 0 && val <= 269)
{
senstvaz = map(val, 0, 269, -50, -1);
}
else if (val >= 270 && val <= 503)
{
senstvaz = map(val, 270, 503, 0, 19) + 2;
}
else if (val >= 504 && val <= 821)
{
senstvaz = map(val, 504, 821, 20, 55) + 2;
}
else if (val >= 822 && val <= 875)
{
senstvaz = map(val, 822, 875, 56, 65) + 2;
}
else if (val >= 876 && val <= 930)
{
senstvaz = map(val, 876, 930, 66, 80) + 2;
}
else if (val >= 931 && val <= 946)
{
senstvaz = map(val, 931, 946, 81, 85) + 2;
}
else if (val >= 947 && val <= 965)
{
senstvaz = map(val, 947, 965, 86, 97) + 2;
}
else if (val >= 966 && val <= 1002)
{
senstvaz = map(val, 966, 1002, 98, 126) + 2;
}
else if (val >= 1003 && val <= 1015)
{
senstvaz = map(val, 1003, 1015, 127, 140) + 2;
}
tmp37 = (analogRead(3) * 5.0 / 1024.0) / 0.02; // tmp37
/////////////////////////////////////////////
/*
if (digitalRead(9) <= 0)
{
ds = (tempSensor.getTemperature()),
lcd.clear(),
lcd.print(ds),
delay(1000);
}
*/
if (Serial.available() > 0) //priem ot kompa
{
int inByte = Serial.read();
if (inByte ==1)
{
peakboost = 0;
inByte =0;
}
}
if (digitalRead(8) <= 0)
{
peakboost = 0; //sbros pikboosta, sbrasivati na minus
peakrpm = 0;
peakspeed = 0;
lcd.clear();
// lcd.setCursor(0, 0);
lcd.print("PEAKS SBROS");
delay(30);
}
////////////////////////////////////////////////////////////////
lcd.clear();
lcd.setCursor(0, 0);
//lcd.print(dinaimpulsov);
lcd.print("V");
lcd.print(voltage,1);
lcd.setCursor(6, 0);
lcd.print("B");
lcd.print(boost);
// lcd.print(taxometr);
//lcd.print(" ");
// lcd.print(mapp);
// lcd.print(" ");
// lcd.print(atmos);
// lcd.print(" ");
// lcd.print(taxo);
lcd.setCursor(0, 1);
lcd.print(dinaimpulsov);
lcd.print(" ");
lcd.print(ValSpCurr);
// lcd.print(boost);
// lcd.print(" ");
// lcd.print(kpa);
// lcd.print(" ");
// lcd.print(pboost);
// lcd.print(" ");
//lcd.print(tmp37);
//////////////////////////////////////////////////////////////////
bytes[0]=(volts); //volts
bytes[1]=(kpa); //turbo
bytes[2]=(pboost); //pboost
bytes[3]=(senstvaz); //senstvaz
// bytes[4] = result & 255;
// bytes[5] = (result & 768) >> 8;
bytes[4] = taxo & 0xFF; // преобразовать в 4-байта
bytes[5] = (taxo & 0xFF00) >> 8;
bytes[6] = (taxo & 0xFF0000) >> 16;
bytes[7] = (taxo & 0xFF000000) >> 24;
Serial.write( bytes,8);
// delay(400);
bytes[0] = 0;
bytes[1] = 0;
bytes[2] = 0;
bytes[3] = 0;
bytes[4] = 0;
bytes[5] = 0;
bytes[6] = 0;
bytes[7] = 0;
}
/*
void inton()
{
}
*/
void int_on()
{
count++; //увеличить счетчик volatile
if (count >= 4)
{
taxometr = micros()-time; //время прихода 6-ти импульсов
time = micros(); //обнулить
// taxometrrr = count;
count = 0;
}
}
void flash() //обработка прерывания таймера
{
}