Go Down

Topic: Read a freqency from an analog pin (Read 3 times) previous topic - next topic

majenko

#25
Nov 14, 2012, 07:24 pm Last Edit: Nov 14, 2012, 07:30 pm by majenko Reason: 1

Now ,it is correct?
Code: [Select]

#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:

Quote from: Wikipedia

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 ...

Quote from: Wikipedia

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.
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

AWOL

Oops, missed the superfluous function prototype.  :*
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

florin

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.

majenko

#28
Nov 14, 2012, 07:39 pm Last Edit: Nov 14, 2012, 07:43 pm by majenko Reason: 1

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.

Quote from: Wikipedia
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.
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

florin

Can make for me a correct program with this library?

Go Up