Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name Elevator
- @outputs Tross
- @outputs CurrentFloor TargetFloor StatusPixel Screen:string
- @inputs F1 F2 F3 F4 F5 F6 F7 F8 F9 F0
- @inputs Del Start Clear
- @persist MaxFloor:normal DifValue:normal UnitsPerFloor:normal RealFloor:normal
- @persist Imprecision:normal NextFloor
- @persist ErrorColor WaitingColor ActionColor
- @persist InAction PError:vector PWait:vector PAction:vector
- @persist DiffBetCurTrg:normal StartFrom:normal
- interval( 50 )
- function normal getFloorByTrossLen( TrossLen, Half )
- {
- return ( Half ? round(TrossLen / UnitsPerFloor) : floor( TrossLen / UnitsPerFloor ) )
- }
- function normal getTrossLenByFloor( Floor )
- {
- return DifValue + Floor * UnitsPerFloor
- }
- function normal typeOfDigit( Digit )
- {
- if( Digit < 10 )
- {
- return 1
- }
- if( (Digit / 10) - ceil(Digit / 10) == 0 )
- {
- return 2
- }
- if( Digit == 0 )
- {
- return 3
- }
- return 4
- }
- function normal packetNumberFromVector( Vector:vector )
- {
- #Number = 255 || 255 << 8 || 255 << 16
- Number = 0
- Number = Vector:z()
- Number = Number || Vector:y() << 8
- Number = Number || Vector:x() << 16
- return Number
- }
- if( first() )
- {
- PError = vec( 255, 0, 0 )
- PAction = vec( 0, 255, 0 )
- PWait = vec( 255, 216, 0 )
- StatusPixel = packetNumberFromVector(PWait)
- UnitsPerFloor = 30
- Imprecision = 0.8
- DifValue = 15.03
- MaxFloor = 20
- NextFloor = 0
- TargetFloor = 0
- InAction = 0
- Tross = DifValue
- Screen = "Waiting your command"
- }
- if( ~Clear )
- {
- TargetFloor = 0
- }
- if( ~Del )
- {
- if( Del )
- {
- TargetFloor = floor(TargetFloor / 10)
- }
- }
- if
- (
- ( ~F1 & F1 ) | (~F2 & F2) |
- ( ~F3 & F3 ) | ( ~F4 & F4 ) |
- ( ~F5 & F5 ) | ( ~F6 & F6 ) |
- ( ~F7 & F7 ) | ( ~F8 & F8 ) |
- ( ~F9 & F9 ) | ( ~F0 & F0 )
- )
- {
- Type = typeOfDigit( TargetFloor )
- State = 0
- Changed = 0
- if( State == 0 )
- {
- State = ~F1 * 1
- }
- if( State == 0 )
- {
- State = F2 * 2
- }
- if( State == 0 )
- {
- State = F3 * 3
- }
- if( State == 0 )
- {
- State = F4 * 4
- }
- if( State == 0 )
- {
- State = F5 * 5
- }
- if( State == 0 )
- {
- State = F6 * 6
- }
- if( State == 0 )
- {
- State = F7 * 7
- }
- if( State == 0 )
- {
- State = F8 * 8
- }
- if( State == 0 )
- {
- State = F9 * 9
- }
- if( State == 0 )
- {
- State = F0 * 0
- Changed = 1
- }
- if( State != 0 | State == 0 & Changed )
- {
- if( Type == 4 )
- {
- TargetFloor = 0
- Type = 3
- }
- if( Type == 3 )
- {
- TargetFloor = State
- }
- elseif( Type == 2 )
- {
- TargetFloor += State
- }
- elseif( Type == 1 )
- {
- TargetFloor = TargetFloor * 10 + State
- }
- }
- }
- CurrentFloor = getFloorByTrossLen( Tross, 1 )
- if( ~Start & Start )
- {
- NextFloor = TargetFloor
- if( NextFloor < MaxFloor )
- {
- InAction = !InAction
- if( InAction )
- {
- Screen = "Let me do my work!"
- StatusPixel = packetNumberFromVector(PAction)
- DiffBetCurTrg = abs(getTrossLenByFloor( CurrentFloor ) - getTrossLenByFloor( NextFloor ))
- StartFrom = NextFloor - CurrentFloor
- if( DiffBetCurTrg < UnitsPerFloor )
- {
- DiffBetCurTrg = UnitsPerFloor
- }
- }
- else
- {
- Screen = "Somethig went wrong?"
- StatusPixel = packetNumberFromVector(PError)
- }
- }
- else
- {
- Screen = "Selected floor is very big"
- StatusPixel = packetNumberFromVector(PError)
- }
- }
- if( ->Tross & ->CurrentFloor & ->TargetFloor & ->Start & InAction)
- {
- Diffirence = abs(getTrossLenByFloor( NextFloor ) - Tross) - ( TargetFloor == 0 ? 0 : 15 )
- RealFloor = getFloorByTrossLen( Tross, 0 )
- DifCurNextFloor = 0
- if( $RealFloor == 0 )
- {
- DifCurNextFloor = abs( getTrossLenByFloor( TargetFloor ) - Tross - DifValue )
- }
- else
- {
- DifCurNextFloor = DiffBetCurTrg
- }
- if( Diffirence > Imprecision )
- {
- Value = abs((sin( DifCurNextFloor / DiffBetCurTrg * 180 )) * 7) + 0.5
- Tross = ( RealFloor < NextFloor ? Tross + Value : Tross - Value )
- }
- else
- {
- InAction = 0
- Screen = "Waiting your command"
- StatusPixel = packetNumberFromVector(PWait)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment