

А я не помню сколько ты мне говорил? Ты мне давно фотки присылал и говорил сколько стоит контроллер.
Код: Выделить всё
unsigned long timerate=100;
unsigned long bufftime;
volatile unsigned int th_buff = 0;
volatile unsigned int th = 0;
double th_correction = 1;
int th_pin=7;
volatile unsigned int sp_buff = 0;
volatile unsigned int sp = 0;
double sp_correction = 1;
int sp_pin=4;
unsigned long sp_bufftime;
unsigned long sp_pulse;
bool sp_pulse_on=false;
unsigned long th_bufftime;
unsigned long th_pulse;
bool th_pulse_on=false;
void setup()
{
attachInterrupt(1, speedometr, RISING);
attachInterrupt(0, tahometr, RISING);
pinMode(th_pin, OUTPUT);
pinMode(sp_pin, OUTPUT);
}
void speedometr(){ sp_buff++; }
void tahometr(){ th_buff++; }
void loop(){ counter(); sp_generate(); th_generate(); }
void counter()
{
if (millis() - bufftime > timerate)
{
bufftime = millis();
sp=sp_buff;
sp_buff=0;
th=th_buff;
th_buff=0;
}
}
void sp_generate()
{
sp_pulse=timerate/sp*1000*sp_correction/2;
if ((micros()-sp_bufftime)>= sp_pulse)
{
sp_bufftime = micros();
if(sp_pulse_on){ digitalWrite(sp_pin, HIGH); sp_pulse_on=false;}
else{ digitalWrite(sp_pin, LOW); sp_pulse_on=true;}
}
}
void th_generate()
{
th_pulse=timerate/th*1000*th_correction/2;
if ((micros()-th_bufftime)>= th_pulse)
{
th_bufftime = micros();
if(th_pulse_on){ digitalWrite(th_pin, HIGH); th_pulse_on=false;}
else{ digitalWrite(th_pin, LOW); th_pulse_on=true;}
}
}
Код: Выделить всё
unsigned long timerate=100;
unsigned long bufftime;
volatile unsigned int th_buff = 0;
volatile unsigned int th = 0;
double th_correction = 1;
int th_pin=7;
volatile unsigned int sp_buff = 0;
volatile unsigned int sp = 0;
double sp_correction = 1;
int sp_pin=4;
unsigned long sp_bufftime;
unsigned long sp_pulse;
bool sp_pulse_on=false;
unsigned long th_bufftime;
unsigned long th_pulse;
bool th_pulse_on=false;
void setup()
{
attachInterrupt(1, speedometr, RISING);
attachInterrupt(0, tahometr, RISING);
pinMode(th_pin, OUTPUT);
pinMode(sp_pin, OUTPUT);
}
void speedometr(){ sp_buff++; }
void tahometr(){ th_buff++; }
void loop(){ counter(); sp_generate(); th_generate(); }
void counter()
{
if (millis() - bufftime > timerate)
{
bufftime = millis();
sp=sp_buff;
sp_buff=0;
th=th_buff;
th_buff=0;
}
}
void sp_generate()
{
sp_pulse=timerate/sp*1000*sp_correction/2;
if ((micros()-sp_bufftime)>= sp_pulse)
{
sp_bufftime = micros();
if(sp_pulse_on){ digitalWrite(sp_pin, HIGH); sp_pulse_on=false;}
else{ digitalWrite(sp_pin, LOW); sp_pulse_on=true;}
}
}
void th_generate()
{
th_pulse=timerate/th*1000*th_correction/2;
if ((micros()-th_bufftime)>= th_pulse)
{
th_bufftime = micros();
if(th_pulse_on){ digitalWrite(th_pin, HIGH); th_pulse_on=false;}
else{ digitalWrite(th_pin, LOW); th_pulse_on=true;}
}
}
Уазовский.Konstantin_s писал(а): ↑13 фев 2023, 23:24 Спидометр похож на УАЗовский? Его можно аккуратно в щиток вставить? Или как сделано?