increase the frequency over 300 hz

hey guys,

my name is raunak and i have to write a program with which i can change the frequency. no matter how so ever the changes i make my frequency is not going over 300Hz.

Here is my program.

String inString = ""; // string to hold input const int ledPin = 9; const int ininder = 5; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); pinMode(ledPin, OUTPUT); pinMode(ininder, INPUT); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } } void loop() { if (Serial.available() > 0) { int inChar = Serial.read();

if (isDigit(inChar)) { inString += (char)inChar; } if (inChar == '\n') { Serial.println(inString.toInt()); // int i = analogRead(ininder); // Serial.println(i); int i = 0; while(i==0){ digitalWrite(ledPin, HIGH); delay(5000/inString.toInt()); delay(1); Serial.println(5000/inString.toInt()); digitalWrite(ledPin, LOW); delay(5000/inString.toInt()); delay(1); analogRead(i); } inString = "" ; }}}

For all our sakes, including yours, please Auto Format your code before posting it and use code tags when you do. Done properly it looks like this

String inString = "";    // string to hold input
const int ledPin = 9;
const int ininder = 5;
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(ininder, INPUT);
  while (!Serial)
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}
void loop()
{
  if (Serial.available() > 0)
  {
    int inChar = Serial.read();

    if (isDigit(inChar))
    {
      inString += (char)inChar;
    }
    if (inChar == '\n')
    {
      Serial.println(inString.toInt());
      // int i = analogRead(ininder);
      // Serial.println(i);
      int i = 0;
      while (i == 0)
      {
        digitalWrite(ledPin, HIGH);
        delay(5000 / inString.toInt());
        delay(1);
        Serial.println(5000 / inString.toInt());
        digitalWrite(ledPin, LOW);
        delay(5000 / inString.toInt());
        delay(1);
        analogRead(i);
      }
      inString = ""
                 ;
    }
  }
}

It does not answer your question but it may make the problem easier to find.

raunak1607: hey guys,

my name is raunak and i have to write a program with which i can change the frequency. no matter how so ever the changes i make my frequency is not going over 300Hz.

For creating square wave output with frequencies in the audible range (32 Hz ... above 20 kHz) better use the tone() function instead of bullshit programming using delay() or delayMicroseconds().

Use https://www.arduino.cc/en/Reference/Tone

You have no means to break out of your WHILE loop and it always works with the same value of inString

There is no need for the WHILE. Allow loop() to do the iteration.

And use millis() rather than delay() for non-blocking timing which will be more accurate. See Several Things at a Time

You should print the value of 5000 / inString.toInt() so you are sure it is doing what you want And have a look at Serial Input Basics

...R