Random number to create a slow chase

瀏覽次數:45 次
跳到第一則未讀訊息

Stuart Hanlon

未讀,
2016年10月25日 凌晨2:58:242016/10/25
收件者:OpenRemote
Hi

No surprise here, yet another Rules question...

(Will someone please just charge me € for doing these?)


With the ability to scene set DMX & SPi universe', I just can't resist trying to get OpenRemote to (slowly) fire off commands to create a simple random chase.


I found this :-


import java.util.Random;

public class RandomNumber {
private int randomNumber;

public void begin() {
this.randomNumber = new Random().nextInt( 100 );
}

public void setValue(final int value) {
this.randomNumber = value;
}

public int getValue() {
return this.randomNumber;
}

}



And I'm wondering how best to use it to create a 6 digit HEX RGB string.


I can easily obtain an interval timer in Velbus, so triggering a rule is straight forward.

(Following is just a thought, not a working rule)

Rule "Random Chase"

When

Sensor "Interval Timer" value == "on"

Then

public class RandomNumber {
private int randomNumber;

public void begin() {
this.randomNumber = new Random().nextInt( 255 );
}

public void setValue(final int value) {
this.randomNumber = value;
}

public int getValue() {
return this.randomNumber;
}

}


[Something to turn the number into a HEX string]


Then

Execute.command ("RGB_Uni0", $HEX)


End

Michal Rutka

未讀,
2016年10月25日 上午10:30:312016/10/25
收件者:OpenRemote

rule "-Generate random 6 digits hex"

timer(int: 0 10s) // Remove this when acting on Event, otherwise it will generate a new random every 10 seconds

when

 // Event(source=="your trigger", value=="on") // Make sure that value is not "on" inbetween, otherwise the rule won't trigger or you need explicitly retract the event

then

  java.util.Random randomGenerator = new java.util.Random();

 execute.command("RGB_Uni0", String.format("%06X", randomGenerator.nextInt(0x1000000)));

end

Stuart Hanlon

未讀,
2016年10月25日 下午4:14:432016/10/25
收件者:OpenRemote
I say :-)


Thanks Michal.

I was thinking that it would be far more complex than that :-)


I'm in an installation right now that I might be able to try that out with :-)


Otherwise, I'll give it a go at home next week.


How much do I owe you now?

Cheers,

Stuart

Stuart Hanlon

未讀,
2017年4月17日 下午4:52:352017/4/17
收件者:OpenRemote
Hi

I'm sorry, I forgot to say thank you for this.


It's been working really well :-)


I've also expanded it to a little single pixel DMX architectural light.

The only issue as that the random numbers it generates tended to be quite small, so the red elements aren't called for very often.


So I gently tweaked the code to generate 3 x 2 digit HEX values to make more use of the full RGB range.


This is the code that's working really well.


execute.command("DMX_Universal-200","pixel.api?uni=5&ordercolour=rgb&onecolour=" + String.format("%02X", randomGenerator.nextInt(0x1000000)) + String.format("%02X", randomGenerator.nextInt(0x1000000)) + String.format("%02X", randomGenerator.nextInt(0x1000000)) + "&start=1&end=1");


Thanks again,


Stuart

Stuart Hanlon

未讀,
2017年5月22日 上午10:38:022017/5/22
收件者:OpenRemote
Hello

For those that are following this thread and are interested in seeing it in action, I made this quick and simple video of an installation I did last year.

youtu.be/_5OZvMJusUI

回覆所有人
回覆作者
轉寄
0 則新訊息