# SQUVARE-WAVE Help

Hello
I am a beginner in arduino programming and need some help.
I need it to program an adjustable squarewave oscillator in the range from 0hz to 500hz with a potentiometer. I don’t know how to make a program in XOD. How can I get 0hz at the output when the potentiometer is in position 0. When the potentiometer is in position 0, the LED must be turned off. When the potentiometer is in position 0.5 at the output, I should get a value of 250hz. Please help

Assuming 500Hz is 1 cycle every 0.002 seconds, this would be correct for what you said you wanted. I’m not sure that is really what you want, though. You are turning the LED to full power, then off and repeating. At slow speeds, this will be a blinking light. At faster speeds, it will flicker. At really fast speeds, it will look like LED is at half brightness.

If what you want is to control the brightness of the LED, the led node already handles this for you. Simply feed the pot output to the led-LUM

Thank you for answering my question. My problem is that i don’t know how to stop the led from blinking. It is necessary when I turn the potentiometer to the minimum that the diode stops flashing completely. when I turn the potentiometer to the opposite side, the LED should start flashing at a value of 1hz, up to 500hz when the potentiometer is at its maximum.
To repeat. When the output value is less than 1hz, or, when the potentiometer is at the minimum, the LED must turn off.

Something like this would be one option:

You will need to adjust the ‘less’ value to check for 1hz; I just picked a random number

If map output is greater than the ‘less’ compare value, then if-else sends 0 to the led-LUM; otherwise, it sends the output of square-wave.

Thank you very much for your help. This works just like i need it to. I am very grateful to you.
I would like to ask one more question. when the potentiometer is at half value how can I get the value of frequency 250hz. When I turn the potentiometer, the frequency value increases logarithmically and not linearly. if there is a solution for that too.

The inverse of logarithmic would be exponential. That would be the ‘pow’ node with pot-VAL linked to pow-EXP. You would have to experiment to see what pow-BASE should be. Your map source values will likely need to change to match output of pow.

It might be more complicated than this since output of POT will be 0-1, so you will be using values <1 for pow-EXP. If you open the led node, you will see it cubes input value to before feeding it to PWM; maybe that would be a good-enough approximation for you instead of using pow.

Sorry…I’m just throwing things out to see if something sticks at this point A google search for “convert logarithmic scale to linear” will provide mathematical details, but can be over-whelming if you are not a math person.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.