How to poll an analog pin until it is "High"

EDIT:

Hello all,

How do i go about implementing a condition like the one below:

 while (analogRead.available(Read Current Value to "val)) {

analogWrite(pin[k], val/4);
}

So basicly the value that i read from the Analog Pin would then adjust brightness of my LED on pin[k]

Thanks.
:slight_smile:

Define what high is, and read repeatedly until that value is the exceeded.

I think this might do it

while (analogRead(A0) <= value) {} // hang here until value is exceeded

AWOL:
Define what high is, and read repeatedly until that value is the exceeded.

I have edited the question,

I need the analog value i read in to determine a duty cycle

analogWrite(9, ADCval/4)

I have edited the question,

To the point of incomprehensibility.

AWOL:
Define what high is, and read repeatedly until that value is the exceeded.

Thanks for the reply,

I have edited the question,I need the analog value i read in to determine a duty cycle

analogWrite(9, ADCval/4)

I don't see analogWrite (pin[k], analogRead (inputPin [k]) / 4); wouldn't work

AWOL:
I don't see analogWrite (pin[k], analogRead (inputPin [k]) / 4); wouldn't work

what wouldn't work?, fading the LED?? i am thinking this is essentially the same as the example below 0.o??

void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }

Hint as to why analogWrite (pin[k], analogRead (inputPin [k]) / 4);is flawed:
==> Why you may need to use the map() function.

BTW - editing the top post makes it VERY hard for others to follow the thread as the earlier version of your question has disappeard, but the answers still stand in the thread. I do not get the connection between making a LED intensity follow an analog input and the triangle wave fader.

Sorry, it was supposed to say "I don't see why .... wouldn't work".
I don't understand the stuff about the while loop in the first post.

analogRead (inputPin [k]) / 4

The /4 takes care of the mapping; shifts 10-bit data into 8-bit value.

Could also write as

analogRead (inputPin [k]) >> 2

:blush: oops.

Thanks for the replies all.

i decided to go with the code from this video [URL: Arduino PWM Tutorial #2 - How to Set PWM Frequency Accurately - YouTube]

void loop()
{
int sensor = analogRead(A0);
analogWrite(9, sensorValue /4);
delay(30);
}

it kinda does what i had in mind!

it kinda does what i had in mind!

It doesn't even compile, so one has to wonder just what you had in mind.