Home » Physical Computing » Spongy, the Elevator Calculator
Spongy, the Elevator Calculator
First Group Project
 
On this project, I teamed with Will Lee ( ) and Maria Michaelides ( ).

» Links

Maria's ecstatic recap can be found here...
... and Will's is here.

» Inside Spongy's BX-24 Brain


» Class Presentation


» BasicX Code

dim direction as byte
dim currentfloor as integer
dim decision as byte
dim direction2 as byte
dim currentfloor2 as integer
dim decision2 as byte
dim avgfloorstop as integer
dim avgfloorspeed as integer
dim avgwalkspeed as integer
dim predictedSpeed as integer
dim predictedSpeed2 as integer

Sub Main()
	avgfloorspeed = 6
	avgfloorstop = 12
	'avgwalkspeed = 60
	avgwalkspeed = 120 ' let's say this is for people on the 8th floor
	do
		call GetInput()
		call CalculateTime()
		call MakeDecision()
	loop
End Sub

sub GetInput()
	direction = getPin(13)
	currentfloor = getADC(14)
	currentfloor = currentfloor \ (1024 \ 11)
	currentfloor = currentfloor + 1
	direction2 = getPin(15)
	currentfloor2 = getADC(16)
	currentfloor2 = currentfloor2 \ (1024 \ 11)
	currentfloor2 = currentfloor2 + 1
end sub

sub CalculateTime()
	dim stops as integer
	dim stops2 as integer
	if (direction = 1) then
		stops = 24 - currentfloor	
	else
		stops = currentfloor
	end if
	if (currentfloor = 1) then 
		stops = 0
	end if
	stops = stops + 4
	if (direction2 = 1) then
		stops2 = 24 - currentfloor2	
	else
		stops2 = currentfloor2
	end if
	if (currentfloor2 = 1) then 
		stops2 = 0
	end if
	stops2 = stops2 + 4

	predictedSpeed = (stops * avgfloorspeed) + ((stops \ 3) * avgfloorstop) ' changed to 1 stop per 4 floors
	predictedSpeed2 = (stops2 * avgfloorspeed) + ((stops2 \ 3) * avgfloorstop)  ' ditto
	debug.print "Elevator 1: "; cStr(currentfloor) ; " (" ; cStr(direction) ; ") EST:" ; cStr(predictedSpeed)
	debug.print "Elevator 2: "; cStr(currentfloor2) ; " (" ; cStr(direction2) ; ") EST:" ; cStr(predictedSpeed2)
	debug.print " "
	'call delay(1.0)
end sub

sub MakeDecision()
	if ( (predictedSpeed <= avgwalkspeed) OR (predictedSpeed2 <= avgwalkspeed) ) then
		call putPin(12,1)
		call putPin(11,0)
	else
		call putPin(11,1)
		call putPin(12,0)
	end if
end sub

Copyright © 2002 James G. Robinson
(and various collaborators, where noted).