iCloud RoboCore

Hey Dominik,

Im not converting the readings to lux, temp of humidity yet. The issue is i dont think its reading the voltages correctly. What I started using originally was a Phidgets lux sensor, continually getting nowhere i decided to use an led for detecting light no light conditions. using a multimeter i measured 0v when there was no light and 1.5v when a high powered led torch was pointed at it. the positive output of the led output was connected to the analog input.of hsens1 being pin 1 and the ground was connected to the ground of the hsens1 point this being pin 2.

i tried both of the examples you mentioned but the readings were not correct. below is the code Im using;

#include <math.h>
#include <hFramework.h>
#include <hCloudClient.h>

int channelStatus[6];
float sensorReading1 = 0;
float sensorReading2 = 0;
float sensorReading3 = 0;
float sensorReading4 = 0;
float sensorReading5 = 0;
//int sensorReading6 = 0;

void cfgHandler() {
    platform.ui.loadHtml({Resource::WEBIDE, "/index.html"});
}

void onValueChangeEvent(hId id, const char* data) {
    
    if (id == "led1") {
        if (atoi(data) == 1) {
            channelStatus[1] = 1;
            LED1.set(1);
            hMot1.setPower(-1000);
        }
        else {
            LED1.set(0);
            hMot1.setPower(0);
            channelStatus[1] = 0;
        }
    }
    if (id == "led2") {
        if (atoi(data) == 1) {
            channelStatus[2] = 1;
            LED2.set(1);
            hMot2.setPower(-1000);
        }
        else {
            channelStatus[2] = 0;
            LED2.set(0);
            hMot2.setPower(0);
        }
    }
    if (id == "led3") {
        if (atoi(data) == 1) {
            channelStatus[3] = 1;
            LED3.set(1);
            hMot3.setPower(-1000);
        }
        else {
            channelStatus[3] = 0;
            LED3.set(0);
            hMot3.setPower(0);
        }
    }
}

void button1_thread_loop() {
    while (true) {
        hBtn1.waitForPressed();
        if (channelStatus[1] == 1) {
            channelStatus[1] = 0;
            LED1.set(0);
            hMot1.setPower(0);
        }
        else {
            channelStatus[1] = 1;
            LED1.on();
            hMot1.setPower(-1000);
        }
        hBtn1.waitForReleased();
    }
}

void button2_thread_loop() {
    while (true) {
        hBtn2.waitForPressed();
        if (channelStatus[2] == 1) {
            channelStatus[2] = 0;
            LED2.set(0);
            hMot2.setPower(0);        
        }
        else {
            channelStatus[2] = 1;
            LED2.set(1);
            hMot2.setPower(-1000);        
        }
        hBtn2.waitForReleased();
    }
}

void hMain() {
    LED3.set(1);
    platform.begin(&Edison);
    platform.ui.setProjectId("9c6f661d18ff2452");
    platform.ui.configHandler = cfgHandler;
    platform.ui.onValueChangeEvent = onValueChangeEvent;
    
    sys.taskCreate(button1_thread_loop);
    sys.taskCreate(button2_thread_loop);

	hSens1.pinIntAdc.enableADC();
    hSens2.pinIntAdc.enableADC();
    hSens3.pinIntAdc.enableADC();
    hSens4.pinIntAdc.enableADC();
    hSens5.pinIntAdc.enableADC();

	while(1) {

	    sensorReading1 = hSens1.pinIntAdc.analogReadVoltage();
	    sensorReading2 = hSens2.pinIntAdc.analogReadVoltage();
	    sensorReading3 = hSens3.pinIntAdc.analogReadVoltage();
	    sensorReading4 = hSens4.pinIntAdc.analogReadVoltage();
	    sensorReading5 = hSens5.pinIntAdc.analogReadVoltage();
	    
	    float temperature = ((sensorReading2 * 0.22222) - 61.11);
	    float humidity = ((sensorReading3 * 0.1906) - 40.2);
	    
        printf("Lux: %f \r", sensorReading1);
        printf("Temperature: %f \r", sensorReading2);
        printf("Humidity: %f \r\n", sensorReading3);
        //printf("%f \r", sensorReading4);
        //printf("%f \r\n", sensorReading5);

	    platform.ui.label("sensor1").setText(" %f ", sensorReading1);
	    platform.ui.label("sensor2").setText(" %f ", sensorReading2);
	    platform.ui.label("sensor3").setText(" %f ", sensorReading3);
	    platform.ui.label("sensor4").setText(" %f ", sensorReading4);
	    platform.ui.label("sensor5").setText(" %f ", sensorReading5);	    
	    sys.delay(500);
	}
}