Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #15 on: November 13, 2012, 04:31:14 pm » |
[quite] I want only a line , wich read frequency...[/quote] Try this: freq=freq_read(pin); //read frequency on pin You are welcome.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35483
Seattle, WA USA
|
 |
« Reply #16 on: November 13, 2012, 04:34:06 pm » |
1.long getFrequency(int pin) { 2.#define SAMPLES 4096 3.long freq = 0; 4.for(unsigned int j=0; j<SAMPLES; j++) freq+= 500000/pulseIn(pin, HIGH, 250000); 5.return freq / SAMPLES; 6.} Is right there on the page you linked to. Surely you can figure out how to call this function.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 242
Posts: 16504
Available for Design & Build services
|
 |
« Reply #17 on: November 13, 2012, 09:05:54 pm » |
Isn't this simple enough? long getFrequency(int pin) { #define SAMPLES 4096 long freq = 0; for(unsigned int j=0; j<SAMPLES; j++) freq+= 500000/pulseIn(pin, HIGH, 250000); return freq / SAMPLES; }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #18 on: November 14, 2012, 06:04:18 am » |
Thanks for answers.  I write the code below: #include <FreqCounter.h>
double frequency;
void setup() { pinMode(5,OUTPUT); pinMode(11,OUTPUT); pinMode(12,OUTPUT); pinMode(15,OUTPUT); pinMode(16,OUTPUT); pinMode(17,OUTPUT);
}
void loop() { long getFrequency(A0); { #define SAMPLES 4096 long freq = 0; for(unsigned int j=0; j<SAMPLES; j++) freq+= 500000/pulseIn(A0, HIGH, 250000); frequency = freq/SAMPLES; if (frequency <1) { digitalWrite(5, HIGH); digitalWrite(11,HIGH);} if (frequency >=1) { digitalWrite(12, HIGH); digitalWrite(15,HIGH);} }
}
No errors, but circuit doesen't work. I have mistakes in the code?
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Edison Member
Karma: 42
Posts: 2200
What a host of balls she had seen: gaity, the brass buttons...
|
 |
« Reply #19 on: November 14, 2012, 06:12:38 am » |
if (frequency <1) { digitalWrite(5, HIGH); digitalWrite(11,HIGH);} if (frequency >=1) { digitalWrite(12, HIGH); digitalWrite(15,HIGH);}
So how do those LEDs ever turn off then? You are turning them on, but never off.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19030
I don't think you connected the grounds, Dave.
|
 |
« Reply #20 on: November 14, 2012, 06:15:43 am » |
The only case where "frequency" is less than one is when it is zero.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35483
Seattle, WA USA
|
 |
« Reply #21 on: November 14, 2012, 06:51:24 am » |
void loop() { long getFrequency(A0); { #define SAMPLES 4096 long freq = 0; for(unsigned int j=0; j<SAMPLES; j++) { freq+= 500000/pulseIn(A0, HIGH, 250000); } frequency = freq/SAMPLES; if (frequency <1) { digitalWrite(5, HIGH); digitalWrite(11,HIGH); } if (frequency >=1) { digitalWrite(12, HIGH); digitalWrite(15,HIGH); } } } Without your atrocious indenting, and with curly braces every where, this is your loop function. So, what exactly is the function prototype in the loop() function for? You don't call the function anywhere, nor do you implement it, so get rid of it. Then, the { and } that follow it are useless. You really don't understand what frequency means, do you?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #22 on: November 14, 2012, 01:14:53 pm » |
Now ,it is correct? #include <FreqCounter.h>
double frequency;
void setup() { pinMode(5,OUTPUT); pinMode(11,OUTPUT); pinMode(12,OUTPUT); pinMode(15,OUTPUT); pinMode(16,OUTPUT); pinMode(17,OUTPUT);
}
void loop() { long getFrequency(A0); { #define SAMPLES 4096 long freq = 0; for(unsigned int j=0; j<SAMPLES; j++) { freq+= 500000/pulseIn(A0, HIGH, 250000); } frequency = freq/SAMPLES; if (frequency <5000) { digitalWrite(5, HIGH); digitalWrite(11,HIGH); } if (frequency >5000) { digitalWrite(12, HIGH); digitalWrite(15,HIGH); } } }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19030
I don't think you connected the grounds, Dave.
|
 |
« Reply #23 on: November 14, 2012, 01:16:59 pm » |
What about turning the LEDs off? What if the average is 5000? Now ,it is correct? You're the one with the hardware, you tell us.
|
|
|
|
« Last Edit: November 14, 2012, 01:20:35 pm by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15314
Measurement changes behavior
|
 |
« Reply #24 on: November 14, 2012, 01:21:34 pm » |
This is a very strange posting thread, maybe well on it's way of becoming a classic.  Lefty
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Edison Member
Karma: 42
Posts: 2200
What a host of balls she had seen: gaity, the brass buttons...
|
 |
« Reply #25 on: November 14, 2012, 01:24:58 pm » |
Now ,it is correct? #include <FreqCounter.h>
double frequency;
void setup() { pinMode(5,OUTPUT); pinMode(11,OUTPUT); pinMode(12,OUTPUT); pinMode(15,OUTPUT); pinMode(16,OUTPUT); pinMode(17,OUTPUT);
}
void loop() { long getFrequency(A0); { #define SAMPLES 4096 long freq = 0; for(unsigned int j=0; j<SAMPLES; j++) { freq+= 500000/pulseIn(A0, HIGH, 250000); } frequency = freq/SAMPLES; if (frequency <5000) { digitalWrite(5, HIGH); digitalWrite(11,HIGH); } if (frequency >5000) { digitalWrite(12, HIGH); digitalWrite(15,HIGH); } } }
Did you actually make any changes...? For your reference: Frequency is the number of occurrences of a repeating event per unit time. It is also referred to as temporal frequency. The period is the duration of one cycle in a repeating event, so the period is the reciprocal of the frequency. For example, if a newborn baby's heart beats at a frequency of 120 times a minute, its period (the interval between beats) is half a second.
... and ... In mathematics, a multiplicative inverse or reciprocal for a number x, denoted by 1/x or x−1, is a number which when multiplied by x yields the multiplicative identity, 1. The multiplicative inverse of a fraction a/b is b/a. For the multiplicative inverse of a real number, divide 1 by the number. For example, the reciprocal of 5 is one fifth (1/5 or 0.2), and the reciprocal of 0.25 is 1 divided by 0.25, or 4. The reciprocal function, the function f(x) that maps x to 1/x, is one of the simplest examples of a function which is self-inverse.
|
|
|
|
« Last Edit: November 14, 2012, 01:30:35 pm by majenko »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19030
I don't think you connected the grounds, Dave.
|
 |
« Reply #26 on: November 14, 2012, 01:29:11 pm » |
Oops, missed the superfluous function prototype. 
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #27 on: November 14, 2012, 01:33:08 pm » |
I am very new at programming. I want to understand what is wrong, but i can't. That's the only mistake? As I turned off the LED-s? The circuit does not light at all, I put any frequency. Should not light up LEDs?  ps: sorry for bad english.
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Edison Member
Karma: 42
Posts: 2200
What a host of balls she had seen: gaity, the brass buttons...
|
 |
« Reply #28 on: November 14, 2012, 01:39:20 pm » |
I am very new at programming. I want to understand what is wrong, but i can't. That's the only mistake? As I turned off the LED-s? The circuit does not light at all, I put any frequency. Should not light up LEDs?  ps: sorry for bad english. There is one more mistake. The program is wrong. Just plain wrong. First steps is to read up on the basic syntax of C so that you can at least have a clue what you're doing. Then, you need to properly define what it is you want to achieve. From that you can break it down into a number of actual steps to achieve your goal. You can then convert those steps into C code in the form of a program. This is called Top Down Programming. Top-down approaches emphasize planning and a complete understanding of the system. It is inherent that no coding can begin until a sufficient level of detail has been reached in the design of at least some part of the system.
|
|
|
|
« Last Edit: November 14, 2012, 01:43:21 pm by majenko »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #29 on: November 14, 2012, 01:55:01 pm » |
Can make for me a correct program with this library?
|
|
|
|
|
Logged
|
|
|
|
|
|