Noob struggling. GOAL - 2 potentiometers to generate a gated pulse signal.

Hi, I'm trying to generate a square wave with 50/50 duty cycle whos frequency is adjusted via a pot hooked up to A0 on my uno. (have managed this quite easily using the "AnalogInput" example)

For the output you could try using the Blink sketch with delayMicroseconds() instead of delay() to get closer timing.

Hello.

I'm trying to generate a gated pulse signal similar to using an astable 555 @50/50 duty with variable frequency AND'ed with a retriggerable monostable for variable duration gating.

I can do it with TTL but would like to implement the same on my UNO R3.

I used the AnalogInput example to get one pot on A0 to blink the onboard LED with adjustable frequency but I realise I dont have a clue how to get the second pot on A1 to gate this.

I suspect I need some code in between analogRead's and the digitalWrite/delays to be able to boolean AND the two together and have been searching all night for examples but have come up short.

I've not much experience coding so any pointers or advice is much appreciated. :slight_smile:

In which of the two posts would you prefer the answers....

this one please! thought I lost the other one half way through.

Then click Report to Moderator in the other thread and ask for the existing reply to get merged into this one.

Yeah reported it and asked for a deletion.

Threads merged.

Have you tried GoForSmoke's suggestion of starting with Blink?

Each time through loop, read pot A0 to determine how much time for the total cycle. Assign the value you calculate to an unsigned long variable called totalTime. Read pot A1 to define what length of time the LED is on during the cycle, and assign it to an unsigned long variable called onTime. The maximum possible value of onTime the same as the value of totalTime.

Now do a 'double Blink' like this:

...
digitalWrite(LEDpin, HIGH);
delayMicroseconds(onTime);
digitalWrite(LEDpin, LOW);
delayMicroseconds(totalTime - onTime);
...

That's about it. Now put this idea into your own code.

Dunravin:
Hello.

I'm trying to generate a gated pulse signal similar to using an astable 555 @50/50 duty with variable frequency AND'ed with a retriggerable monostable for variable duration gating.

I can do it with TTL but would like to implement the same on my UNO R3.

I used the AnalogInput example to get one pot on A0 to blink the onboard LED with adjustable frequency but I realise I dont have a clue how to get the second pot on A1 to gate this.

I suspect I need some code in between analogRead's and the digitalWrite/delays to be able to boolean AND the two together and have been searching all night for examples but have come up short.

I've not much experience coding so any pointers or advice is much appreciated. :slight_smile:

I saw no code and a square wave described, not 2 though from the title I figured it'd get to that.

The Arduino IDE Example to use for 2 is BlinkWithoutDelay but with some changes where it is not right, all of the time variables should be unsigned as in unsigned long and that example mixes in longs with unsigned longs.

I would suggest using micros() instead of millis() for frequency timing especially if the frequencies are higher than 5 or 10 Hz.