Member #635630

Member Since: January 6, 2015

Country: United States

  • This project proved to be EXACTLY what I needed to make a sine-wave generator for testing the brainwave monitor I'm designing. Here is how I modified it. The line:

    while ((millis() - Mils) < 1) {};
    

    keeps the frequency correct second by second. And the

    byte multiplier;
    

    determines the number of cycles per second. "multiplier" can be changed as the program runs, by plugging a grounded jumper into the different Arduino inputs that you have pre-set in this sketch.

    float in, out;
    const int LED = 11;
    unsigned long Mils = millis();
    byte multiplier = 1;
    
    void setup()
    {
    pinMode(2, INPUT_PULLUP);
    pinMode(3, INPUT_PULLUP);
    pinMode(4, INPUT_PULLUP);
    pinMode(5, INPUT_PULLUP);
    }
    
    void loop()
    {
      if (digitalRead(2) == LOW)
        multiplier = 1;
      else if (digitalRead(3) == LOW)
        multiplier = 10;
      else if (digitalRead(4) == LOW)
        multiplier = 20;
      else if (digitalRead(5) == LOW)
        multiplier = 40;
      for (in = 0; in < 6.283; in += (multiplier * 0.006283))
      {
        while ((millis() - Mils) < 1) {};
        Mils += 1;
        out = sin(in) * 127.5 + 127.5; // 127.5
        analogWrite(LED,out);
      }
    }
    

    I use it with the first circuit shown at: http://www.wa4dsy.net/robot/active-filter-calc Entering 50 as the number for both input parameters of their calculator, gives the perfect values needed to filter this waveform

No public wish lists :(