Hello,
We are currently working on a project of a rc electric vehicle that has LED bars on the side that need to display the speed of the car. The car makes use of a tachometer to count the revolutions. We think we already have quite a good setup of the code to calculate the speed:
volatile int rpm = 0;
volatile float interval = 0;
volatile float time_last = 0;
float velocity;
void setup() {
pinMode (5, INPUT); // input of the RPM Sensor
pinMode (6, OUTPUT);
pinMode (7, OUTPUT); // LED bar1
pinMode (8, OUTPUT);
pinMode (18, OUTPUT);
pinMode (19, OUTPUT); // LED bar2
pinMode (20, OUTPUT);
pinMode (30, OUTPUT);
pinMode (31, OUTPUT); // LED bar3
pinMode (32, OUTPUT);
pinMode (42, OUTPUT);
pinMode (43, OUTPUT); // LED bar4
pinMode (44, OUTPUT);
attachInterrupt(5, interruption, FALLING);
}
void loop() {
rpm = 60*(1000/interval);
velocity = (0.376991*rpm*3.6)/60;
}
void interruption(){
interval = (millis()-time_last);
time_last = millis();
}
Now we are at the point that we have to transfer the info to the LED bars on the car. Each LED bar will display the same thing, so we just need to try one first and then the rest will work out.
this is how the pins are connected:
signal pin
rpm sensor output 5
clock, LED bar 1 6
serial data in, LED bar 1 7
latch, LED bar 1 8
clock, LED bar 2 18
serial data in, LED bar 2 19
latch, LED bar 2 20
clock, LED bar 3 30
serial data in, LED bar 3 31
latch, LED bar 3 32
clock, LED bar 4 42
serial data in, LED bar 4 43
latch, LED bar 4 44
We do not really understand how the three inpunts of each LED bars work, the relationship between them, some advice/help would be really appreciated!