Anyone here a genius with the RedPower Computer language?
I'm making an elevator with button presses on ground and first floor. At the moment the button on ground makes it go up and on the 1st floor it sends it down. However, what I'd ultimately like to achieve is if the lift isn't on your level, a button press will call the lift to your level also.
Here is the code I have done so far that works well at the moment:
: higher
8 IOX!
15 TICKS
0 IOX!
5 TICKS
;
: lower
16 IOX!
15 TICKS
0 IOX!
5 TICKS!
;
: up
4 0 DO higher LOOP
;
: down
4 0 DO lower LOOP
;
: var VARIABLE ;
var $active !
0 $active !
: ACTIVE
IOX@ AND
0 = IF
0
ELSE
-1
THEN
;
: listen
BEGIN
0 $active !
2 ACTIVE IF
up
CR ." Up Button Activated" CR
1 $active !
THEN
4 ACTIVE IF
down
CR ." Down Button Activated" CR
1 $active !
THEN
$active @ 1 = IF
1 IOX!
10 TICKS
0 IOX!
10 TICKS
THEN
30 TICKS
AGAIN
;
So is there an easy way for the system to detect what floor the lift currently resides on before deciding to whether go up or down? I have a short YouTube video of it working that is currently processing that should help visualise it. I'll post it when it finishes.
Anyone here a genius with the RedPower Computer language?
I'm making an elevator with button presses on ground and first floor. At the moment the button on ground makes it go up and on the 1st floor it sends it down. However, what I'd ultimately like to achieve is if the lift isn't on your level, a button press will call the lift to your level also.
Here is the code I have done so far that works well at the moment:
: higher
8 IOX!
15 TICKS
0 IOX!
5 TICKS
;
: lower
16 IOX!
15 TICKS
0 IOX!
5 TICKS!
;
: up
4 0 DO higher LOOP
;
: down
4 0 DO lower LOOP
;
: var VARIABLE ;
var $active !
0 $active !
: ACTIVE
IOX@ AND
0 = IF
0
ELSE
-1
THEN
;
: listen
BEGIN
0 $active !
2 ACTIVE IF
up
CR ." Up Button Activated" CR
1 $active !
THEN
4 ACTIVE IF
down
CR ." Down Button Activated" CR
1 $active !
THEN
$active @ 1 = IF
1 IOX!
10 TICKS
0 IOX!
10 TICKS
THEN
30 TICKS
AGAIN
;
So is there an easy way for the system to detect what floor the lift currently resides on before deciding to whether go up or down? I have a short YouTube video of it working that is currently processing that should help visualise it. I'll post it when it finishes.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.