Hej Martin,
undskyld ::)
Ja, jeg tror at din pyroelectro-link er perfekt til dit projekt.
Hvis du vil ikke have noget filter skriv:
rpm = 60*(1000000/(time));
i stedet for
//5 Sample Moving Average To Smooth Out The Data
rpm_array[0] = rpm_array[1];
rpm_array[1] = rpm_array[2];
rpm_array[2] = rpm_array[3];
rpm_array[3] = rpm_array[4];
rpm_array[4] = 60*(1000000/(time));
//Last 5 Average RPM Counts Eqauls....
rpm = (rpm_array[0] + rpm_array[1] + rpm_array[2] + rpm_array[3] + rpm_array[4]) / 5;
Jeg kan dog ikke gennemskue hvordan jeg får samtlige omdrejninger på nederste linie, jeg mener... den har jo talt omdrejningerne.
#include <LiquidCrystal.h>
LiquidCrystal lcd(3, 5, 9, 10, 11, 12);
volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};
volatile int cnt = 0;
// digital pin 3 has a pushbutton (reset counts) attached to it. Give it a name:
int resetCntButton = 3;
void setup()
{
// make the pushbutton's pin an input:
pinMode(resetCntButton, INPUT);
//Digital Pin 2 Set As An Interrupt
attachInterrupt(0, fan_interrupt, FALLING);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("RPM:");
}
//Main Loop To Calculate RPM and Update LCD Display
void loop()
{
int rpm = 0;
while(1){
//Slow Down The LCD Display Updates
delay(400);
//Clear The First Row
lcd.setCursor(0, 0);
lcd.print("RPM: ");
//Update The Rpm Count
lcd.setCursor(4, 0);
lcd.print(rpm);
//Clear The Second Row
lcd.setCursor(0, 1);
lcd.print("CNT: ");
lcd.setCursor(4, 1);
lcd.print(cnt);
//Update The RPM
if(time > 0)
{
rpm = 60*(1000000/(time));
}
// Reset the counter by pressing the resetCntButton
if (digitalRead(resetCntButton))
{
cnt = 0;
}
}
}
//Capture The IR Break-Beam Interrupt
void fan_interrupt()
{
time = (micros() - time_last);
time_last = micros();
//Count the rotations
cnt ++;
}
gerd
hey
har en lille ændring til Gerd's fine forslag der fjerner at RPM bliver stående
#include <LiquidCrystal.h>
LiquidCrystal lcd(3, 5, 9, 10, 11, 12);
volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};
volatile int cnt = 0;
// digital pin 3 has a pushbutton (reset counts) attached to it. Give it a name:
int resetCntButton = 3;
void setup()
{
// make the pushbutton's pin an input:
pinMode(resetCntButton, INPUT);
//Digital Pin 2 Set As An Interrupt
attachInterrupt(0, fan_interrupt, FALLING);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("RPM:");
}
//Main Loop To Calculate RPM and Update LCD Display
void loop()
{
int rpm = 0;
while(1){
//Slow Down The LCD Display Updates
delay(400);
//Clear The First Row
lcd.setCursor(0, 0);
lcd.print("RPM: ");
//Update The Rpm Count
lcd.setCursor(4, 0);
lcd.print(rpm);
//Clear The Second Row
lcd.setCursor(0, 1);
lcd.print("CNT: ");
lcd.setCursor(4, 1);
lcd.print(cnt);
//Update The RPM
if(time > 0)
{
rpm = 60*(1000000/(time));
}
else rpm = 0;
// Reset the counter by pressing the resetCntButton
if (digitalRead(resetCntButton))
{
cnt = 0;
}
}
}
//Capture The IR Break-Beam Interrupt
void fan_interrupt()
{
time = (micros() - time_last);
time_last = micros();
//Count the rotations
cnt ++;
}
men ellers som Gerd siger så skal du have en pull-down på din knap altså sådan her.:
(http://elektronik-forum.dk/gallery/32_27_10_13_9_17_28.jpeg)
MVH