Home automation programming with .NET MF - Automatic door controled by GPIO


1. Start "SPL script editor for MSRDS" and add SPL simulation script
  1. Add simulation script on the editor as follows.



      
    MFEmulator    emul1
    	/TargetEmulator:SPLMFConsoleEmulator
    	/Procedure_GPIOChanged:proc_gpio
    
    StartSimulationEngine  "SimState/basicsim.xml"
    
    AddNewEntity    ent0  	/Position:0  0.05  -1.0
    	/IsKinematic:true
    
    	AddBoxShape  
    		/Dimensions:5.0  0.1  8.0  	/Mass:10
    
    AddNewEntity    ent1  	/Position:0.52  1.1  0.0
    	/DisableRendering:true
    	/ParentEntity:ent0
    
    	AddBoxShape  
    		/Dimensions:1.0  2.0  0.1  	/Mass:0.1
    
    AddNewEntity    ent2  	/Position:-0.52  1.1  0.0
    	/DisableRendering:true
    	/ParentEntity:ent0
    
    	AddBoxShape  
    		/Dimensions:1.0  2.0  0.1  	/Mass:0.1
    
    AddGraphicSpriteEntity    sprite1
    	/ParentEntity:ent1
    	/Position:0  0  0
    	/Width:1.0
    	/Height:2.0
    	/TextureWidth:320
    	/TextureHeight:240
    	/BackgroundColor:10  10  30  255
    	/SpritePivotType:Fixed
    
    AddGraphicSpriteEntity    sprite2
    	/ParentEntity:ent2
    	/Position:0  0  0
    	/Width:1.0
    	/Height:2.0
    	/TextureWidth:320
    	/TextureHeight:240
    	/BackgroundColor:10  10  30  255
    	/SpritePivotType:Fixed
    
    AddJoint    joint1
    	/ChildEntity:ent1
    	/JointPosition:0  0  0
    	/XLinear:position  500000  100000  0  1000000
    
    AddJoint    joint2
    	/ChildEntity:ent2
    	/JointPosition:0  0  0
    	/XLinear:position  500000  100000  0  1000000
    
    FlushScript  
    
    wait 2000
    
    procedure proc_gpio
    	if (value.Id == "port6")
    	{
    		if (value.State)
    		{
    			//open the door
    			ent1.JointLinearPosition(-1.0, 0, 0)
    			ent2.JointLinearPosition(1.0, 0, 0)	
    		}
    		else
    		{
    			//close the door
    			ent1.JointLinearPosition(0, 0, 0)
    			ent2.JointLinearPosition(0, 0, 0)	
    		}
    	}
    end  
    
      


  2. Save script.

  3. Press "F5" key or click "Run" icon.




2. Add a GPIO port for the control of automatic door
  1. Choose "Application" tab from the "SPL MF Console Emulator".

  2. Add below script on the editor box of "Application" tab.



      
    OutputPort    port6
    	/Pin:6
    	/InitialState:false
    
      


  3. Click "Send to MF Application" button



3. Open the door
  1. Choose "Application" tab from the "SPL MF Console Emulator".

  2. Add below script on the editor box of "Application" tab.



      
    port6.Write(true)
    
      


  3. Click "Send to MF Application" button

  4. You can see the door in simulation environment is opend




4. Close the door
  1. Choose "Application" tab from the "SPL MF Console Emulator".

  2. Add below script on the editor box of "Application" tab.



      
    port6.Write(false)
    
      


  3. Click "Send to MF Application" button

  4. You can see the door in simulation environment is closed