Pages: 1 [2]   Go Down
Author Topic: Wanting to build a frequency generator.  (Read 1667 times)
0 Members and 1 Guest are viewing this topic.
Oz
Offline Offline
God Member
*****
Karma: 3
Posts: 659
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess I am doing it this way to keep my hand in at programming.

As you can see I am not good, and the only way to get better is to keep programming.

I have got a better sketch, but I think the values used in the tone( ) command are not right.

Code:
int frequency1;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop()
{
  // put your main code here, to run repeatedly:
  int tone_frequency;
  int stack;
  if (Serial.available() > 0)
  {
      //
      Serial.print ("1 This is the raw data ");
      stack = Serial.read();
      Serial.println(stack);
      if (stack != ';')
//      while (stack != ';')
      {
          frequency1  = (stack - 48);
          Serial.print("frequency so far ");
          Serial.println(frequency1);
      }
      Serial.print ("2 This is the raw data ");
      stack = Serial.read();
      Serial.println(stack);
      while (stack != ';')
      {
          frequency1 = frequency1 *10 + (stack - 48);
          Serial.print("frequency so far ");
          Serial.println(frequency1);
          stack = Serial.read();
      }
     
      //frequency1  = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
      //run_time_hr  = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));

          Serial.print ("The frequency you entered is ");
          Serial.println (frequency1);
          Serial.println("================================");
         
          noTone(8);
          tone(8,frequency1);
          delay(500);
          if (frequency1 == 0)
          {
             noTone(8);
          }
  }
     
}


I was trying to get the bigger part in the "while stack != ';'" part, but am falling over a bit there.

Also I need this ';' delimiter because I don't (yet) know how to detect "EOL" (or C/R) to see if enter has been pressed.

If I enter 20 - to get 20hz - the output is too higher a frequency.  Shall have to do some digging and see what is going on.
Logged

Oz
Offline Offline
God Member
*****
Karma: 3
Posts: 659
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Seems the tone( ) function has a lower limit of 140 Hz.

DRATS!

Back to the drawing board.



Logged

Pages: 1 [2]   Go Up
Jump to: