OK update:
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// //
// Producer : RMFMellink //
// e-mail : ... //
// website : ... //
// //
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// The following code aims to recieve a pulsed
// input with a variable frquency and output the
// number of pulses per minute (rpm) to a shifting
// register which drives up to 30 LED's with the
// overal brightness of the LEDs driven by a PWM
// signal via a transistor.
//////////////////////////////////////////////////
////////VARIABLE AND PIN DECLARATION//////////////
//////////////////////////////////////////////////
//Shift register declaration
int latchPin = 8;
//Latch pin declare
int clockPin = 12;
//Clock pin declare
int dataPin = 11;
//Data pin declare
//RPM inputs
int rpmpulseinput = 1;
//RPM input declare
int pulsesdetected = 0;
//RPM counted
int lastpulsestatedetected = 0;
//RPM last pulse state detected (0=LOW and 1=HIGH)
//////////////////////////////////////////////////
///////////////FUNCTION DECLARATION///////////////
//////////////////////////////////////////////////
int LEDon(int LEDnumber){
//Turns on LED number X with 0ms delay
Serial.print("LED ");
Serial.print(LEDnumber, DEC);
Serial.print(" has been called.");
//Prints LED 10 has been called.
digitalWrite(latchPin, LOW);
//Set latch pin to LOW
shiftOut(dataPin, clockPin, MSBFIRST, LEDnumber);
//Send data to IC
digitalWrite(latchPin, HIGH);
//Set latch pin to HIGH to set changes in IC
}
int LEDcumlon(int numberofLEDtolight,int delaytime){
//Lights all LED's up with numberofLEDtolight with
//delay of delaytime in ms between LEDs
for(int LED1=1;LED1=numberofLEDtolight;LED1++){
//Turns on 1 LED with delaytime ms delay
LEDon(LED1);
//Turns on loop number LED
delay(delaytime);
//Delays the next LED coming on
}
}
int pulseread(){
//Addes one to the pulses detected if the input
//changes state
if(digitalRead(rpmpulseinput)==LOW){
//If the input has a pulse on it
if(digitalRead(lastpulsestatedetected=0)){
//If the output has changed then add one to the
//number of pulses detected
pulsesdetected=pulsesdetected+1;
}
}
}
int pulseoutput(){
//Resets the pulse count every 1 second so the number
//of pulses per second is output
Serial.println(pulsesdetected);
//Print the number of detected pulses
delay(1000);
//Delay 1 second
pulsesdetected = 0;
//Clears pulses detected
}
//////////////////////////////////////////////////
///////////////////MAIN CODE//////////////////////
//////////////////////////////////////////////////
void setup() {
Serial.begin(96000);
Serial.println("Arduino Connected to M1330 via USB");
//start com with (serial)
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
//Connect to shift register IC
pinMode(rpmpulseinput, INPUT);
// sets the digital pin as input
digitalWrite(rpmpulseinput, HIGH);
// turns on the internal pull up
LEDcumlon(15,500);
//Output test of IC of
//X (LEDs to be turned on)
//Y (milliseconds of delay between turning on LEDs)
}
void loop()
{
pulseread();
//Counts the number of pulses
pulseoutput();
//Outputs the number of pulses in 1 second
////////////////////////////////////
//Do more stuff here all functions//
////////////////////////////////////
}
//////////////////////////////////////////////////
////////////////////END OF CODE///////////////////
//////////////////////////////////////////////////