Arduino Interfacing for RPM Lights

Open a thread for a question about the simulator control software.
If you cannot receive any data in the input setup use the upper two forums!

Arduino Interfacing for RPM Lights

Postby R4MP4G3RXD » Sat 17. Jan 2015, 22:00

Hello! I have an Arduino Leonardo, and things just don't work for some reason... I'm trying to make RPM Lights with a 74hc595 and a couple of leds.
The code is the following:(please keep in mind I did NOT write this code, I found it somewhere on the internet.)
Code: Select all
int Rpm;
int RpmLight;
char kind_of_data;

int latchpin = 8; // connect to pin 8 on the '595
int clockpin = 4; // connect to pin 4 on the '595
int datapin = 7; // connect to pin 7 on the '595


void setup(){

  pinMode(latchpin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(datapin, OUTPUT);

  Serial.begin(9600);
}

void loop(){
  //****************************** READ DATA FROM SERIAL ******************************
  while (Serial.available() > 0)
  {

    kind_of_data = Serial.read();
    if (kind_of_data == 'R' ) Read_Rpm();
   
 
    digitalWrite(latchpin, LOW);
    shiftOut(datapin, clockpin, MSBFIRST, RpmLight);
    digitalWrite(latchpin, HIGH);
  }
}


//****************************** READ DATA FROM SERIAL END ******************************


void Read_Rpm(){

  int Rpm = 0;
  delay(2);
  int Rpm100 = Serial.read();
  delay(2);
  int Rpm10 = Serial.read();
  delay(2);
  int Rpm1= Serial.read();
 
  Rpm100 = ((Rpm100)-48)*100;
  Rpm10  = ((Rpm10)-48)*10;
  Rpm1   = ((Rpm1)-48)*1;
  if (Rpm10 < 0 && Rpm1 < 0){Rpm100 = Rpm100/100;Rpm10 = 0;Rpm1 = 0;}
  if (Rpm1 < 0){Rpm100 = Rpm100/10;Rpm10 = Rpm10/10;Rpm1 = 0;}
     
  Rpm = Rpm100+Rpm10+Rpm1;
 
 
  if (Rpm > 108) { RpmLight = 0;}
  if (Rpm > 92 && Rpm <= 108) { RpmLight = 1;}
  if (Rpm > 76 && Rpm <= 92) { RpmLight = 3;} 
  if (Rpm > 60 && Rpm <= 76) { RpmLight = 7;}
  if (Rpm > 54  && Rpm <= 60){ RpmLight = 15;}
  if (Rpm > 48 && Rpm <= 54){ RpmLight = 31;}
  if (Rpm > 32 && Rpm <= 48){ RpmLight = 63;}
  if (Rpm > 16 && Rpm <= 32){ RpmLight = 127;}
  if (Rpm > 0 && Rpm <= 10){ RpmLight = 255;}
}

And I have my x-sim set up like so:
Image
Image
Image

If you know where I failed, please take the time and correct me!
Thanks for your help!
-Valentin
R4MP4G3RXD
 
Posts: 5
Joined: Fri 31. Jan 2014, 20:13
Has thanked: 0 time
Been thanked: 0 time

Re: Arduino Interfacing for RPM Lights

Postby MotorMola » Wed 21. Jan 2015, 20:26

Hi Valentin,

Did you already solve your problem? I use a ATMega 2560 to control a BMW e36 cluster and a home made RPM lights pcb. I think it's difficult to get this code (found somewhere on the inet) working properly in some hours if you have not all information about it. It's costumizend for this user, maybe a special game or hardware. So you should build it step by step.
- First you should know, if your output setup works -> write one pin to "HIGH" to see that communication X-sim software - arduino is working. (I used pin 13, because HIGH is indicated by an LED on the arduino pcb).
- Then you have to know, which values you receive from X-sim for RPM, so that you can costumize to your lights. I can write a lot of information here, but I don't know if it's helpful. If you have any questions, write a pm. Maybe we can get it working together.

by the way "Serial.begin(9600) is "wrong" -> you set the rate to 115200 in your X-sim output setup. Change it in your arduino program.

Greetz Martin
MotorMola
 
Posts: 1
Joined: Mon 22. Sep 2014, 17:04
Has thanked: 0 time
Been thanked: 0 time


Return to Converter questions

Who is online

Users browsing this forum: No registered users and 3 guests