/*Larmar med ljud och LED-ljus om en ABS signal räknar fler pulser än dom andra = lågt lufttryck i ett däck.*/
const int larmPin = 7; // the number of the Buzzer pin
const int VFpin = 10; //
const int HFpin = 11; //
const int VBpin = 12; //
const int HBpin = 13; // blinkar vid uppstart
int VFvalue = 0; //ABS värde VF osv.
int HFvalue = 0;
int VBvalue = 0;
int HBvalue = 0;
int ABSvalue = 0;
unsigned long oldMillis = 0;
unsigned long kollMillis = 0; //timer för att nolla kollräknaren.
float punka = 1 ; // 0.95 skillnad som ger indikering på punktering
int Fel = 5; //antal Fel 5 innan larmindikering
int kollVF = 0; int kollHF = 0; int kollVB = 0; int kollHB = 0;
int kollVFtot = 0; int kollHFtot = 0; int kollVBtot = 0; int kollHBtot = 0;
int timer = 500; // tid som ABS pulserna räknas 250
volatile int SensorCountVF = 0; // Speed Sensor pulse count
void AddSensorCountVF() { // This is the subroutine that is called when interrupt 0 goes high
SensorCountVF++; // Increment SensorCount by 1
}
volatile int SensorCountHF = 0; // Speed Sensor pulse count
void AddSensorCountHF() { // This is the subroutine that is called when interrupt 0 goes high
SensorCountHF++; // Increment SensorCount by 1
}
volatile int SensorCountVB = 0; // Speed Sensor pulse count
void AddSensorCountVB() { // This is the subroutine that is called when interrupt 0 goes high
SensorCountVB++; // Increment SensorCount by 1
}
volatile int SensorCountHB = 0; // Speed Sensor pulse count
void AddSensorCountHB() { // This is the subroutine that is called when interrupt 0 goes high
SensorCountHB++; // Increment SensorCount by 1
}
void setup() {
pinMode(larmPin, OUTPUT);
pinMode(VFpin, OUTPUT);
pinMode(HFpin, OUTPUT);
pinMode(VBpin, OUTPUT);
pinMode(HBpin, OUTPUT);
//digitalWrite(VFpin, HIGH); delay(500);digitalWrite(HFpin, HIGH); delay(500);digitalWrite(VBpin, HIGH); delay(500);digitalWrite(HBpin, HIGH);
//delay(500);
//digitalWrite(VFpin, LOW); delay(500);digitalWrite(HFpin, LOW);delay(500); digitalWrite(VBpin, LOW);delay(500); digitalWrite(HBpin, LOW);
attachInterrupt(0, AddSensorCountHB, RISING); // HB Interrupt 0 is on digital pin 3
attachInterrupt(1, AddSensorCountVB, RISING); // VB Interrupt 1 pin 2
attachInterrupt(3, AddSensorCountHF, RISING); // HF Interrupt 3 is on digital pin 1
attachInterrupt(2, AddSensorCountVF, RISING); // VF Interrupt 2 pin 0
}
void loop() {
//------------ räknar pulser ABS senorerna
if(millis()-oldMillis > timer && millis()-oldMillis < timer*2 ){
attachInterrupt(2, AddSensorCountVF, RISING); // Interrupt 0 is on digital pin 3
if (VFvalue < SensorCountVF){
VFvalue = SensorCountVF;
}
attachInterrupt(3, AddSensorCountHF, RISING); // Interrupt 1 is on digital pin 2
if (HFvalue < SensorCountHF){
HFvalue = SensorCountHF;
}
attachInterrupt(1, AddSensorCountVB, RISING); // Interrupt 3 is on digital pin 1
if (VBvalue < SensorCountVB){
VBvalue = SensorCountVB;
}
attachInterrupt(0, AddSensorCountHB, RISING); // Interrupt 2 is on digital pin 0
if (HBvalue < SensorCountHB){
HBvalue = SensorCountHB;
}
ABSvalue=(VFvalue+HFvalue+VBvalue+HBvalue)/4 ;
}
// ---------------------- AntiSpinn--------ej aktiverat än...
/* if (VFvalue-5 >HFvalue && VFvalue-5 >HBvalue && VFvalue-5 >VBvalue) // Om VF roterar snabbare än övriga
{ larmSend(); digitalWrite(VFpin, HIGH); delay(5000); digitalWrite(VFpin, LOW);
digitalWrite(VFpin, HIGH); delay(5000); digitalWrite(VFpin, LOW);
}
if (HFvalue-5 >VFvalue && HFvalue-5 >HBvalue && HFvalue-5 >VBvalue) // Om HF roterar snabbare än övriga
{ larmSend(); digitalWrite(HFpin, HIGH); delay(5000); digitalWrite(HFpin, LOW);
digitalWrite(HFpin, HIGH); delay(5000); digitalWrite(HFpin, LOW);
}
*/
//---------------------------------------Kontroll av ABS signaler varannan sek. 4*500ms
if(millis()-oldMillis > timer*4 && millis()-oldMillis < timer*5 ) {
// -------------ABS sensor fel/avbrott
if (VFvalue<5 && HFvalue>200 && HBvalue>200 && VBvalue>200) // om VF saknar pulser medans dom andra visar mer än 200
{ digitalWrite(VFpin, HIGH); //digitalWrite(VBpin, HIGH); digitalWrite(HBpin, HIGH); // inget larmljud, bilen bör visa ABS fel.
delay(10000); digitalWrite(VFpin, LOW); digitalWrite(HFpin, LOW); digitalWrite(VBpin, LOW); digitalWrite(HBpin, LOW);
}
if (HFvalue<5 && VFvalue>200 && HBvalue>200 && VBvalue>200) //HF
{ digitalWrite(HFpin, HIGH); //digitalWrite(VBpin, HIGH); digitalWrite(HBpin, HIGH);
delay(10000); digitalWrite(VFpin, LOW); digitalWrite(HFpin, LOW); digitalWrite(VBpin, LOW); digitalWrite(HBpin, LOW);
}
if (VBvalue<5 && HFvalue>200 && HBvalue>200 && VFvalue>200) //VB
{ digitalWrite(VBpin, HIGH); //digitalWrite(HFpin, HIGH); digitalWrite(HBpin, HIGH);
delay(10000); digitalWrite(VFpin, LOW); digitalWrite(HFpin, LOW); digitalWrite(VBpin, LOW); digitalWrite(HBpin, LOW);
}
if (HBvalue<5 && HFvalue>200 && VFvalue>200 && VBvalue>200) //HB
{ digitalWrite(HBpin, HIGH); //digitalWrite(HFpin, HIGH); digitalWrite(VBpin, HIGH);
delay(10000); digitalWrite(VFpin, LOW); digitalWrite(HFpin, LOW); digitalWrite(VBpin, LOW); digitalWrite(HBpin, LOW);
}
//---------------------------------------Kontroll av ABS signaler mer än 30km/t och 150km/t skillnad på 1 puls.
if (VFvalue>200 && HFvalue>200 && HBvalue>200 && VBvalue>200){ //120 ca 20 km/h, 760 ca 110 km/tim
if (VFvalue<800 && HFvalue<800 && HBvalue<800 && VBvalue<800){ //max värde 800 150 km/h
// Jämför VF med dom andra värdena
if (VFvalue-punka>HFvalue && VFvalue-punka>HBvalue && VFvalue-punka>VBvalue)
{ kollVF=kollVF+1 ; // räknar med 1 vid varje fel
if (kollVF == Fel) // kontroll x antal gånger innan fel indikeras
{ kollVFtot=kollVFtot+1 ;larmSend(); digitalWrite(HFpin, HIGH); digitalWrite(VBpin, HIGH); digitalWrite(HBpin, HIGH); delay(10000);
digitalWrite(VFpin, LOW); digitalWrite(HFpin, LOW); digitalWrite(VBpin, LOW); digitalWrite(HBpin, LOW); kollVF=0;
}} // Jämför HF med dom andra värdena
if (HFvalue-punka>VFvalue && HFvalue-punka>HBvalue && HFvalue-punka>VBvalue)
{ kollHF=kollHF+1 ;
if (kollHF == Fel) // kontroll 3 gånger innan fel indikeras
{ kollHFtot=kollHFtot+1 ;larmSend(); digitalWrite(VFpin, HIGH); digitalWrite(VBpin, HIGH); digitalWrite(HBpin, HIGH); delay(10000);
digitalWrite(VFpin, LOW); digitalWrite(HFpin, LOW); digitalWrite(VBpin, LOW); digitalWrite(HBpin, LOW); kollHF=0;
} } // Jämför VB med dom andra värdena
if (VBvalue-punka>VFvalue && VBvalue-punka>HFvalue && VBvalue-punka>HBvalue)
{ kollVB=kollVB+1 ;
if (kollVB == Fel) // kontroll 3 gånger innan fel indikeras
{ kollVBtot=kollVBtot+1 ;larmSend(); digitalWrite(VFpin, HIGH); digitalWrite(HFpin, HIGH); digitalWrite(HBpin, HIGH); delay(10000);
digitalWrite(VFpin, LOW); digitalWrite(HFpin, LOW); digitalWrite(VBpin, LOW); digitalWrite(HBpin, LOW); kollVB=0;
} } // Jämför HB med dom andra värdena
if (HBvalue-punka>VFvalue && HBvalue-punka>HFvalue && HBvalue-punka>VBvalue)
{ kollHB=kollHB+1 ;
if (kollHB == Fel) // kontroll 3 gånger innan fel indikeras
{ kollHBtot=kollHBtot+1 ;larmSend(); digitalWrite(VFpin, HIGH); digitalWrite(HFpin, HIGH); digitalWrite(VBpin, HIGH); delay(10000);
digitalWrite(VFpin, LOW); digitalWrite(HFpin, LOW); digitalWrite(VBpin, LOW); digitalWrite(HBpin, LOW); kollHB=0;
} } } }
//---------Om den indikerar fel fler än 3 ggr indikerar den fel hela tiden
if (kollVFtot == 3) // kontroll x antal gånger innan fel indikeras
{ digitalWrite(HFpin, HIGH); digitalWrite(VBpin, HIGH); digitalWrite(HBpin, HIGH); kollVF=0; }
if (kollHFtot == 3) // kontroll 3 gånger innan fel indikeras
{ digitalWrite(VFpin, HIGH); digitalWrite(VBpin, HIGH); digitalWrite(HBpin, HIGH); kollHF=0; }
if (kollVBtot == 3) // kontroll 3 gånger innan fel indikeras
{ digitalWrite(VFpin, HIGH); digitalWrite(HFpin, HIGH); digitalWrite(HBpin, HIGH); kollVB=0; }
if (kollHBtot == 3) // kontroll 3 gånger innan fel indikeras
{ digitalWrite(VFpin, HIGH); digitalWrite(HFpin, HIGH); digitalWrite(VBpin, HIGH); kollHB=0; }
//---------------------------------------Nollar sensor värdena och ny tid efter kontrollerna
SensorCountVF = 0; SensorCountHF = 0; SensorCountVB = 0; SensorCountHB = 0;
oldMillis = millis();
VFvalue = 0; HFvalue = 0; VBvalue = 0; HBvalue = 0;
}
//---------------------------------------nollar felräknaren vart 30 sek
if(millis()-kollMillis > 30000) { // 15 sek intervall
kollVF = 0; kollHF = 0; kollVB = 0; kollHB = 0;
kollMillis = millis(); // nollar koll timern§
}
}
void larmSend() { // larm vid punkterings indikering
digitalWrite(larmPin, HIGH); delay(800);
digitalWrite(larmPin, LOW);
}
--------------------------------------------------------------------------------------------------------
// Test mjukvara för TPMS Däcktrycks övervakning. Uppdat2014/12 nya tider..
#include <LiquidCrystal.h>
const int larmPin = 7; // the number of the Buzzer pin
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
int backlightPin = 6; //pwm pin
int brightness = 150; //0-255 0=svagtljus
int kontrastPin =5; //pwm pin
int kontrast = 50; //från 0-110 110=svagt
int VFvalue = 0; //ABS värde VF osv.
int HFvalue = 0;
int VBvalue = 0;
int HBvalue = 0;
int ABSvalue = 0; //medelvärdet för testning
unsigned long oldMillis = 0;
unsigned long kollMillis = 0; //timer för att nolla kontrollräknaren.
float punka = 1 ; // 7 (5=0.95) antal pulser som skiljer och ger indikering på punktering
int Fel = 5; //antal Fel innan larmindikering
int kollVF = 0; int kollHF = 0; int kollVB = 0; int kollHB = 0;
int timer = 500 ; // tid som ABS pulserna räknas (250)
volatile int SensorCountVF = 0; // Speed Sensor pulse count
void AddSensorCountVF() { // This is the subroutine that is called when interrupt 0 goes high
SensorCountVF++; // Increment SensorCount by 1
}
volatile int SensorCountHF = 0; // Speed Sensor pulse count
void AddSensorCountHF() { // This is the subroutine that is called when interrupt 0 goes high
SensorCountHF++; // Increment SensorCount by 1
}
volatile int SensorCountVB = 0; // Speed Sensor pulse count
void AddSensorCountVB() { // This is the subroutine that is called when interrupt 0 goes high
SensorCountVB++; // Increment SensorCount by 1
}
volatile int SensorCountHB = 0; // Speed Sensor pulse count
void AddSensorCountHB() { // This is the subroutine that is called when interrupt 0 goes high
SensorCountHB++; // Increment SensorCount by 1
}
void setup() {
pinMode(larmPin, OUTPUT);
pinMode(backlightPin, OUTPUT);
pinMode(kontrastPin, OUTPUT);
attachInterrupt(0, AddSensorCountVF, RISING); // VF Interrupt 0 is on digital pin 3
attachInterrupt(1, AddSensorCountHF, RISING); // HF Interrupt 1 pin 2
attachInterrupt(3, AddSensorCountVB, RISING); // VB Interrupt 3 is on digital pin 1
attachInterrupt(2, AddSensorCountHB, RISING); // HB Interrupt 2 pin 0
lcd.begin(20,4);
}
void loop() {
analogWrite(kontrastPin, kontrast);
analogWrite(backlightPin, brightness);
//------------ räknar pulser ABS senorerna
if(millis()-oldMillis > timer && millis()-oldMillis < timer*2 ){
attachInterrupt(0, AddSensorCountVF, RISING); // Interrupt 0 is on digital pin 3
if (VFvalue < SensorCountVF){
VFvalue = SensorCountVF;
}
attachInterrupt(1, AddSensorCountHF, RISING); // Interrupt 1 is on digital pin 2
if (HFvalue < SensorCountHF){
HFvalue = SensorCountHF;
}
attachInterrupt(3, AddSensorCountVB, RISING); // Interrupt 3 is on digital pin 1
if (VBvalue < SensorCountVB){
VBvalue = SensorCountVB;
}
attachInterrupt(2, AddSensorCountHB, RISING); // Interrupt 2 is on digital pin 0
if (HBvalue < SensorCountHB){
HBvalue = SensorCountHB;
}
ABSvalue=(VFvalue+HFvalue+VBvalue+HBvalue)/4 ;
}
//---------------------------------------Kontroll av ABS signaler mer än 120-400 och skillnad på 5 %
if(millis()-oldMillis > timer*4 && millis()-oldMillis < timer*6 ) {
if (VFvalue>220 && HFvalue>220 && HBvalue>220 && VBvalue>220){ //170 ca 50 km/h, 360 ca 110 km/tim
if (VFvalue<800 && HFvalue<800 && HBvalue<800 && VBvalue<800){ //max värde 400 150 km/h
lcd.setCursor(0,2); //delay(2000);
lcd.print(" "); // 20(16) tecken för att rensa
lcd.setCursor(0,2); //kolumn,rad
lcd.print(ABSvalue-VFvalue); lcd.setCursor(5,2); lcd.print(ABSvalue-HFvalue);lcd.setCursor(10,2);
lcd.print(ABSvalue-VBvalue);lcd.setCursor(15,2); lcd.print(ABSvalue-HBvalue);
// Jämför VF med dom andra värdena
if (VFvalue-punka>HFvalue && VFvalue-punka>HBvalue && VFvalue-punka>VBvalue)
{ kollVF=kollVF+1 ;
if (kollVF == Fel) // kontroll 3 gånger innan fel indikeras
{ larmSend();
lcd.setCursor(0, 1); //kolumn,rad
lcd.print("Punka V-fram");lcd.print(VFvalue-punka);delay(8000);
lcd.clear(); kollVF=0; larmSend();
}} // Jämför HF med dom andra värdena
if (HFvalue-punka>VFvalue && HFvalue-punka>HBvalue && HFvalue-punka>VBvalue)
{ kollHF=kollHF+1 ;
if (kollHF == Fel) // kontroll 3 gånger innan fel indikeras
{ larmSend();
lcd.setCursor(0, 1); //kolumn,rad
lcd.print("Punka H-fram");lcd.print(HFvalue-punka);delay(8000);
lcd.clear(); kollHF=0;
} } // Jämför VB med dom andra värdena
if (VBvalue-punka>VFvalue && VBvalue-punka>HFvalue && VBvalue-punka>HBvalue)
{ kollVB=kollVB+1 ;
if (kollVB == Fel) // kontroll 3 gånger innan fel indikeras
{ larmSend();
lcd.setCursor(0, 1); //kolumn,rad
lcd.print("Punka V-bak");lcd.print(VBvalue-punka);delay(8000);
lcd.clear(); kollVB=0;
} } // Jämför HB med dom andra värdena
if (HBvalue-punka>VFvalue && HBvalue-punka>HFvalue && HBvalue-punka>VBvalue)
{ kollHB=kollHB+1 ;
if (kollHB == Fel) // kontroll 3 gånger innan fel indikeras
{ larmSend();
lcd.setCursor(0, 1); //kolumn,rad
lcd.print("Punka H-bak");lcd.print(HBvalue-punka);delay(8000);
lcd.clear(); kollHB=0;
} } } }
//---------------------------------------Nollar sensor värdena och ny tid
SensorCountVF = 0; SensorCountHF = 0; SensorCountVB = 0; SensorCountHB = 0;
oldMillis = millis();
lcd.setCursor(0,1); //delay(2000);
lcd.print(" "); // 20(16) tecken för att rensa
VFvalue = 0; HFvalue = 0; VBvalue = 0; HBvalue = 0;
lcd.setCursor(0,3); lcd.print(oldMillis/1000);lcd.setCursor(5,3);lcd.print(kollMillis/1000);//delay(2000);
}
//---------------------------------------nollar kontrollen vart 5 sek 250*20
if(millis()-kollMillis > 150000) { // 15000 = 15 sek intervall
kollVF = 0; kollHF = 0; kollVB = 0; kollHB = 0;
kollMillis = millis(); // nollar koll timern§
lcd.setCursor(0,2); //delay(200);
lcd.print(" ");
}
//--------------LCD presentation------------
lcd.setCursor(0,0); //delay(200);
lcd.print("VFi"); lcd.setCursor(5,0); lcd.print("HFi");lcd.setCursor(10,0); lcd.print("VBi");lcd.setCursor(15,0); lcd.print("HBi");
lcd.setCursor(0,1); //delay(200);
lcd.print(VFvalue); lcd.setCursor(5,1); lcd.print(HFvalue);lcd.setCursor(10,1); lcd.print(VBvalue);lcd.setCursor(15,1); lcd.print(HBvalue);
lcd.setCursor(10,3); //lcd.print(oldMillis);//delay(2000);
lcd.print(kollVF);lcd.print(kollHF);lcd.print(kollVB);lcd.print(kollHB); //display av koll värdena TEST
}
void larmSend() { // larm vid punkterings indikering
digitalWrite(larmPin, HIGH); delay(300);
digitalWrite(larmPin, LOW);
}
Inga kommentarer:
Skicka en kommentar