package com.ociweb.grove;
import static com.ociweb.iot.grove.GroveTwig.Button;

import com.ociweb.iot.maker.CommandChannel;
import com.ociweb.iot.maker.DeviceRuntime;
import com.ociweb.iot.maker.Hardware;
import com.ociweb.iot.maker.IoTSetup;
import com.ociweb.iot.maker.Port;
import com.ociweb.gl.api.GreenCommandChannel;

import static com.ociweb.iot.grove.GroveTwig.*;

import static com.ociweb.iot.maker.Port.*;

public class IoTApp implements IoTSetup
{
    ///////////////////////
    //Connection constants 
    ///////////////////////
    // // by using constants such as these you can easily use the right value to reference where the sensor was plugged in
      
    private static final Port BUTTON_PORT = D3;
    private static final Port RELAY_PORT  = D7;
    
    @Override
    public void declareConnections(Hardware c) {
        ////////////////////////////
        //Connection specifications
        ///////////////////////////
        
        // // specify each of the connections on the harware, eg which component is plugged into which connection.        
              
        c.connect(Button, BUTTON_PORT); 
        c.connect(Relay, RELAY_PORT);         
        //c.connect(LightSensor, LIGHT_SENSOR_PORT); 
        //c.connect(LED, LED_PORT);        
        c.useI2C();
        
    }


    @Override
    public void declareBehavior(DeviceRuntime runtime) {
        //////////////////////////////
        //Specify the desired behavior
        //////////////////////////////
        
        //  //Use lambdas or classes and add listeners to the runtime object
        //  //CommandChannels are created to send outgoing events to the hardware
        //  //CommandChannels must never be shared between two lambdas or classes.
        //  //A single lambda or class can use mulitiple CommandChannels for cuoncurrent behavior
        
        
                final CommandChannel channel1 = runtime.newCommandChannel(GreenCommandChannel.DYNAMIC_MESSAGING);
        //        //this digital listener will get all the button press and un-press events 
                runtime.addDigitalListener((port, connection, time, value)->{ 
        //            
        //            //connection could be checked but unnecessary since we only have 1 digital source
        //          
                	channel1.setValue(RELAY_PORT, value);
                	//{
                        //keep the relay on or off for 1 second before doing next command
                        //channel1.block(RELAY_PORT, 1000); 		
                    //}
                	
                 });
    }
        
  
}

@@ -30,298 +30,31 @@
 ort 
-static com.ociweb.iot.grove.GroveTwig.Button;%0A%0Aimport com.ociweb.iot.maker.CommandChannel;%0Aimport com.ociweb.iot.maker.DeviceRuntime;%0Aimport com.ociweb.iot.maker.Hardware;%0Aimport com.ociweb.iot.maker.IoTSetup;%0Aimport com.ociweb.iot.maker.Port;%0Aimport com.ociweb.gl.api.GreenCommandChannel;%0A
+com.ociweb.iot.maker.*;
 %0Aimp
@@ -98,17 +98,16 @@
 Twig.*;%0A
-%0A
 import s
@@ -192,815 +192,247 @@
     
-///////////////////////%0A    //Connection constants %0A    ///////////////////////%0A    // // by using constants such as these you can easily use the right value to reference where the sensor was plugged in%0A      %0A    private static final Port BUTTON_PORT = D3;%0A    private static final Port RELAY_PORT  = D7;%0A    %0A    @Override%0A    public void declareConnections(Hardware c) %7B%0A        ////////////////////////////%0A        //Connection specifications%0A        ///////////////////////////%0A        %0A        // // specify each of the connections on the harware, eg which component is plugged into which connection.        %0A              %0A        c.connect(Button, BUTTON_PORT); %0A        c.connect(Relay, RELAY_PORT);         %0A        //c.connect(LightSensor, LIGHT_SENSOR_PORT); %0A        //c.connect(LED, LED_PORT);
+private static final Port BUTTON_PORT = D3;%0A    private static final Port RELAY_PORT  = D7;%0A    %0A    @Override%0A    public void declareConnections(Hardware c) %7B%0A        c.connect(Button, BUTTON_PORT); %0A        c.connect(Relay, RELAY_PORT); 
     
@@ -460,25 +460,15 @@
 ();%0A
-        %0A
     %7D%0A%0A
-%0A
     
@@ -542,496 +542,9 @@
     
-    //////////////////////////////%0A        //Specify the desired behavior%0A        //////////////////////////////%0A        %0A        //  //Use lambdas or classes and add listeners to the runtime object%0A        //  //CommandChannels are created to send outgoing events to the hardware%0A        //  //CommandChannels must never be shared between two lambdas or classes.%0A        //  //A single lambda or class can use mulitiple CommandChannels for cuoncurrent behavior%0A        %0A        %0A        
+%0A
     
@@ -609,28 +609,8 @@
 nel(
-GreenCommandChannel.
 DYNA
@@ -637,337 +637,83 @@
     
-//        //this digital listener will get all the button press and un-press events %0A                runtime.addDigitalListener((port, connection, time, value)-%3E%7B %0A        //            %0A        //            //connection could be checked but unnecessary since we only have 1 digital source%0A        //          %0A                %09
+runtime.addDigitalListener((port, connection, time, value)-%3E%7B %0A            
 chan
@@ -725,16 +725,24 @@
 setValue
+AndBlock
 (RELAY_P
@@ -755,185 +755,98 @@
 alue
-);%0A                %09//%7B%0A                        //keep the relay on or off for 1 second before doing next command%0A                        //channel1.block(RELAY_PORT, 1000); %09%09%0A
+ == 1, 500); //500 is the amount of time in milliseconds that                             
     
@@ -865,12 +865,11 @@
     
-//%7D%0A
+   
     
@@ -884,10 +884,8 @@
     
-%09%0A
     
@@ -901,28 +901,53 @@
     
-%7D);%0A    %7D%0A        %0A  
+    //delays a future action%0A        %7D);%0A    %7D
 %0A%7D%0A

Create IoTApp.java