Calculation problem  "*"

hello everyone

can i set a number that if the number is in a specific range, and then show the specific value ?

like
if ( 400 < x < 500) Serial.println("450");
could i use this one ?

thanks Groove

i have changed the subject, sorry about that :frowning:

[

if ( (x > 400) [glow]&&[/glow] ( x < 500)) Serial.println("450");

Thanks Groove :slight_smile:

How about this one

if ((x < 10) && ( x < 5)) Serial.println("400" || "500");

i would like to print the value randomly, sometimes 400 or 500

could this code on the above ?

and i have a problem with uploading the code
when i uploaded a new code once, i attempted to uploade another one
it told me that the usb port is being used, i can't upload again unless i restart the computer....

Serial.println((analogRead (unconnectedPin) & 1) ? "400" : "500");

ic
how about the problem, do you know what it is ?

it is showing me this
In function 'void loop()':
error: 'unconnectedPin' was not declared in this scop

"unconnectedPin" is something you have to define.
Hopefully, you'll have a spare analogue input.

Or you could use "micros () & 1" instead, if you've used all your analogue pins.

"unconnectedPin" is something you have to define.
Hopefully, you'll have a spare analogue input.

but i just want to print the value
here's the situation
i don't have any input, if i would like to print the value randomly between 400 and 500, is it possible to do it ?

void setup()
{
Serial.begin(9600);
}
void loop()
{
  int x = 2;
  double y = x * 10;
  if (y > 3) Serial.println("400" or "500"); // this is the value that i would like to print, 400 or 500, when the value of y is larger than 3.

  }
Serial.println((micros () &1) ? "400" : "500");

Is about the simplest way of getting a mostly random number in the range 0..1

Alternately you can use the rand() function

srand(); // Seed the random number generator
int mynum = rand() & 100; // A number between 0 and 100;

if (mynum > 90) { Serial.print("Apples"); }

I didn't realize that the arduino language had it's own random() stuff built in (slaps forhead for not googling first). Check out: http://arduino.cc/en/Reference/Random

Serial.println((micros () &1) ? "400" : "500");

Is about the simplest way of getting a mostly random number in the range 0..1

It looks to me like micros only returns even values. :cry:

OK, so "micros() & 2" :-[

When I wrote that micros only returns even values I failed to mention that the value is always a multiple of four. It will have to be... "micros() & 4".

Because of the nature of AVR processors, it is quite possible that an expression like "micros() & 4" will return a repetitive (non-random) pattern. random is a safer choice.