//////////////////////////////////////////////////
//////////////////////////////////////////////////
// //
// Producer : RMFMellink //
// e-mail : XXX //
// //
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//////////////////////////////////////////////////
/////////////////START UP CODE////////////////////
//////////////////////////////////////////////////
int latchPin = 8; //Latch pin declare
int clockPin = 12; //Clock pin declare
int dataPin = 11; //Data pin declare
int rpmpulseinput = 1; //RPM input declare
int pulsesdetected = 0; //RPM counted
int lastpulsestatedetected = 0;//RPM last pulse state detected
void setup() {
//start com with (serial)
Serial.begin(96000);
Serial.println("Arduino Connected to M1330 via USB");
//Connect to shift register IC
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(rpmpulseinput, INPUT);
// sets the digital pin as input
digitalWrite(rpmpulseinput, HIGH);
// turns on the internal pull up
//Output test of IC
}
//////////////////////////////////////////////////
///////////////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 LEDtest(int numberofLEDtolight,int delaytime){
//Lights all LED's up with numberofLEDtolight with delay of delaytime in ms
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(){
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(){
Serial.println(pulsesdetected);
//Print the number of detected pulses
delay(1000);
//Delay 1 second
pulsesdetected = 0;
//Clears pulses detected
}
//////////////////////////////////////////////////
///////////////////MAIN CODE//////////////////////
//////////////////////////////////////////////////
void loop()
{
pulseread();
pulseoutput();
//Do more stuff here all functions
}
//////////////////////////////////////////////////
////////////////////END OF CODE///////////////////
//////////////////////////////////////////////////