Hi all,
Have been working through this for a while now and am still finding some issues, so I was hoping a post might be able to shed some light on the problems I've been having. A quick bit of background.
The project I'm working on is for a set of sequential shift lights for my car that come on one by one as the revs (rpm) rises.
The circuit diagram is below, as is the code I'm using. Not shown on the diagram, but I'm using 1k ohm (I think) resistors with each LED.
I get a response from the Arduino and can upload the code, but the shift lights don't seem to be coming on when I rev the car. I was wondering if anyone has any ideas about the code and if they can see any glaring errors at all? Maybe the board isn't picking up revs correctly?
Anyway, here it is and thanks in advance.
Sean
int rev = 12;
int ledGr1 = 5;
int ledGr2 = 13;
int ledGr3 = 11;
int ledG1 = 6;
int ledRo = 3;
int ledBl = 10;
int ledAll = 8;
unsigned long duration;
unsigned long rpm;void setup(){
Serial.begin(19200);
pinMode(8, OUTPUT);
pinMode(rev, INPUT);
}
void loop(){
Serial.print("Drehzahl: ");
Serial.println(rpm);
duration = pulseIn(rev, HIGH);
rpm = 30000000 / duration;if (rpm > 11500 && rpm < 20000) {
digitalWrite(ledAll, HIGH);
delay(5);
digitalWrite(ledAll, LOW);
delay(80);
}
if (rpm > 5000) analogWrite(ledGr1, 5);
if (rpm < 4950 || rpm > 20000) analogWrite(ledGr1, 0);
if (rpm > 6500) analogWrite(ledGr2, 5);
if (rpm < 6450 || rpm > 20000) analogWrite(ledGr2, 0);
if (rpm > 8000) analogWrite(ledGr3, 5);
if (rpm < 5950 || rpm > 20000) analogWrite(ledGr3, 0);
if (rpm > 9000) analogWrite(ledG1, 7);
if (rpm < 89500 || rpm > 20000) analogWrite(ledG1, 0);
if (rpm > 10000) analogWrite(ledRo, 10);
if (rpm < 9950 || rpm > 20000) analogWrite(ledRo, 0);
if (rpm > 11000) analogWrite(ledBl, 5);
if (rpm < 10950 || rpm > 20000) analogWrite(ledBl, 0);
delay(50);
}
