Go Down

Topic: Wanting to build a frequency generator. (Read 2512 times) previous topic - next topic

lost_and_confused

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: [Select]

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.

lost_and_confused

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

DRATS!

Back to the drawing board.




Go Up