package com.ociweb.grove;


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

import com.ociweb.iot.maker.Hardware;
import com.ociweb.iot.grove.Grove_LCD_RGB;
import com.ociweb.iot.maker.CommandChannel;
import com.ociweb.iot.maker.DeviceRuntime;
import com.ociweb.iot.maker.IoTSetup;
import com.ociweb.iot.maker.Port;
import static com.ociweb.iot.maker.Port.*;
import static com.ociweb.iot.grove.GroveTwig.AngleSensor;

import com.ociweb.gl.api.GreenCommandChannel;

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 LED_PORT    = D2;
    //private static final Port RELAY_PORT  = D7;
    private static final Port LIGHT_SENSOR_PORT= A2;
    
    public int brightness = 255;
    
    public static void main( String[] args ) {
        DeviceRuntime.run(new IoTApp());
    }
    @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 lcdScreenChannel = runtime.newCommandChannel(GreenCommandChannel.DYNAMIC_MESSAGING);
    	runtime.addAnalogListener((port, time, durationMillis, average, value)->{
     		
	    			
    		lcdScreenChannel.setValue(LIGHT_SENSOR_PORT, value);

    		System.out.println(value);
	    		   		
    		
    	});
    }
        
  
}

@@ -19,18 +19,16 @@
 .grove;%0A
-%0A%0A
 import s
@@ -67,17 +67,16 @@
 Twig.*;%0A
-%0A
 import c
@@ -99,631 +99,101 @@
 ker.
-Hardware;%0Aimport com.ociweb.iot.grove.Grove_LCD_RGB;%0Aimport com.ociweb.iot.maker.CommandChannel;%0Aimport com.ociweb.iot.maker.DeviceRuntime;%0Aimport com.ociweb.iot.maker.IoTSetup;%0Aimport com.ociweb.iot.maker.Port;%0Aimport static com.ociweb.iot.maker.Port.*;%0Aimport static com.ociweb.iot.grove.GroveTwig.AngleSensor;%0A%0Aimport com.ociweb.gl.api.GreenCommandChannel;%0A%0Apublic class IoTApp implements IoTSetup%0A%7B%0A    ///////////////////////%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    //
+*;%0Aimport static com.ociweb.iot.maker.Port.*;%0A%0Apublic class IoTApp implements IoTSetup%0A%7B%0A    
 priv
@@ -218,32 +218,35 @@
 ort 
-BUTTON
+LIGHT_SENSOR
 _PORT
- 
 = 
-D3
+A2
 ;%0A    
-//
 priv
@@ -276,19 +276,16 @@
 ED_PORT 
-   
 = D2;%0A  
@@ -285,19 +285,21 @@
  D2;%0A   
- //
+%0A    
 private 
@@ -315,121 +315,72 @@
 nal 
-Port RELAY_PORT  = D7;%0A    private static final Port LIGHT_SENSOR_PORT= A2;%0A    %0A    public int brightness = 255;
+int darkValue = 350; //Light reading that will turn on the light
 %0A   
@@ -541,347 +541,8 @@
 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);
     
@@ -597,17 +597,16 @@
 R_PORT);
- 
 %0A       
@@ -606,18 +606,16 @@
         
-//
 c.connec
@@ -633,46 +633,83 @@
 PORT
-);        %0A        c.useI2C();
+, 200); //200 is the rate in milliseconds to update the device data
 %0A    %7D%0A%0A
 %0A   
@@ -704,17 +704,16 @@
 %0A    %7D%0A%0A
-%0A
     @Ove
@@ -779,492 +779,8 @@
 ) %7B%0A
-        //////////////////////////////%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
     
@@ -850,28 +850,8 @@
 nel(
-GreenCommandChannel.
 DYNA
@@ -949,25 +949,8 @@
 -%3E%7B%0A
-     %09%09%0A%09    %09%09%09%0A
     
@@ -978,27 +978,18 @@
 tValue(L
-IGHT_SENSOR
+ED
 _PORT, v
@@ -996,12 +996,23 @@
 alue
+ %3C darkValue
 );%0A
-%0A
     
@@ -1044,28 +1044,8 @@
 e);%0A
-%09    %09%09   %09%09%0A    %09%09%0A
     
@@ -1059,18 +1059,6 @@
   %7D%0A
-        %0A  %0A
 %7D%0A

Create IoTApp.java