half way through tonight.. Got a template cut out of a bit of corex which I'm going to draw up in inventor and and get my cnc to cut out when I get it up and running. I'll also add a lambo motif cnc'd out.
Should look a lot better out of the 3mm abs black stuff I've got.
I also coded up the software that will read the pulse from the speedo and control the batwings and spoiler.. untested but this is it so far..
What the code does is...
Waiting 1 minute after starting and if the car is moving it does the following;
under 55mph puts the batwings up
over 65mph puts the batwings down
standing still for over 30 seconds puts the batwings down
under 30mph puts the spoiler down
over 50mph puts the spoiler up
int relayPin1 = 7; // Spoiler Up
int relayPin2 = 8; // Spoiler Down
int relayPin3 = 9; // Batwings
const int hardwareCounterPin = 5; // input pin connect speedo pulse to this
const int ledPin = 13;
const int samplePeriod = 1000; // the sample period in milliseconds
unsigned int count;
float mph;
unsigned int imph;
int roundedMph;
int previousMph;
unsigned long startTime;
unsigned long pastTime;
boolean batwing = false;
boolean spoiler = false;
void setup()
{
Serial.begin(9600); // So we can monitor whats going on via USB
pinMode(ledPin,OUTPUT); // Just for the LED
// hardware counter setup (see ATmega data sheet for details)
TCCR1A=0; // reset timer/counter control register A
// Lets make sure that the spoiler and batwings are down
pinMode(relayPin1, OUTPUT); // sets the digital pin as output
pinMode(relayPin2, OUTPUT); // sets the digital pin as output
pinMode(relayPin3, OUTPUT); // sets the digital pin as output
digitalWrite(relayPin3, LOW); // disconnects negative from batwings to put them down
spoilerdown(); // sets spoiler down (just incase anything funny happend)
startTime = millis();
pastTime = millis();
}
void loop()
{
digitalWrite(ledPin, HIGH);
// start the pulse counting for 1 seconds
bitSet(TCCR1B ,CS12); // Counter Clock source is external pin
bitSet(TCCR1B ,CS11); // Clock on rising edge
delay(samplePeriod);
digitalWrite(ledPin, LOW);
// stop the counting
TCCR1B = 0;
count = TCNT1;
TCNT1 = 0; // reset the hardware counter
mph = (count/11.1)*10;
imph = (unsigned int) mph;
int x = imph / 10;
int y = imph % 10;
// Round to whole mile per hour
if(y >= 5){
roundedMph = x + 1;
}else{
roundedMph = x;
}
if(x == 0){roundedMph = 0;} //anything below 1 mph show 0 mph
if((roundedMph - previousMph) < 30){previousMph = roundedMph;} // just a little saftey.
//batwings
if (millis() > (startTime + 60000)){ //wait for a minute before operating the batwings after startup
if (previousMph > 0){
if (previousMph < 55){ if (batwing == false){digitalWrite(relayPin3, HIGH); Serial.println("Batwing UP"); batwing = true;}} // open batwings if less than 55mph
if (previousMph > 65){ if (batwing == true){digitalWrite(relayPin3, LOW); Serial.println("Batwing DOWN"); batwing = false;)) // close batwings if more then 65mph so they dont blow off
pastTime = millis();
} else {
if (millis() > (pastTime + 30000)){digitalWrite(relayPin3, LOW); Serial.println("Batwing DOWN"); batwing = false;} // close bat wings if stopped more than 30 seconds
}
}
//spoiler
if (previousMph < 30){ //Spoiler down at 30mph
if (spoiler == true){spoilerdown();}
}
if (previousMph > 50){ //Spoiler up at 50mph
if (spoiler == false){spoilerup();}
}
previousMph = roundedMph;
Serial.println(roundedMph);
}
void spoilerup()
{
//make sure the relays are off
digitalWrite(relayPin1, LOW);
digitalWrite(relayPin2, LOW);
delay(200);
digitalWrite(relayPin1, HIGH);
delay(4000); // spolier should now be up after 4 seconds
digitalWrite(relayPin1, LOW);
Serial.println("Spoiler UP");
spoiler = true;
}
void spoilerdown()
{
//make sure the relays are off
digitalWrite(relayPin1, LOW);
digitalWrite(relayPin2, LOW);
delay(200);
digitalWrite(relayPin2, HIGH);
delay(4500); // spolier should now be down after 4 seconds
digitalWrite(relayPin2, LOW);
Serial.println("Spoiler DOWN");
spoiler = false;
}
Will load it up later and give it a test :-)
I've also finished off my rear grille by fitting some led bulbs and securing my rear camera :-)
still lots to do!