float randomNUM;
float VOLTAGE;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(2,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
randomNUM = random(256);
Serial.print("Random Number: ");
Serial.print(randomNUM);
Serial.print(",");
VOLTAGE = (randomNUM*5)/256;
Serial.print("In terms of voltage:");
Serial.println(VOLTAGE);
if(randomNUM>=0 && randomNUM<=41)
{
analogWrite(2,randomNUM);
Serial.println("Should be LOW");
}
else if(randomNUM>=118 && randomNUM<=255)
{
analogWrite(2,randomNUM);
Serial.println("Should be HIGH");
}
else
{
Serial.println("This is not acceptable");
}
delay(5000);
}