gy-30

antoniorrg/gy-30/gy-30

Node for using the gy-30 light sensor
gy-30
@/gy-30
Node for using the gy-30 light sensor
UPDpulse
gy-30
Light
DONE
UPD
DONEpulse
Lightnumber
Value of the light intensity
To use the node in your project you should have the antoniorrg/gy-30 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD require "https://github.com/SV-Zanshin/BME680"
#include <Wire.h>
#define ADDR 0b0100011

node {
    // Internal state variables defined at this level persists across evaluations
    Number foo;
    uint8_t bar = 5;

    void evaluate(Context ctx) {
        bar += 42;

        if (isSettingUp()) {
            // This run once
            foo = (Number)(bar + 1);
        }

  if (!isInputDirty<input_UPD>(ctx))
  return;
        int val;
        val = 0;

Wire.begin();
        
delay(100);
        
Wire.beginTransmission(ADDR);
Wire.write(0b00000111);
Wire.endTransmission();
Wire.beginTransmission(ADDR);
Wire.write(0b00100000);
Wire.endTransmission();

delay(120);

Wire.requestFrom(ADDR, 2); // 2byte every time

for (val = 0; Wire.available() >= 1; ) {

char c = Wire.read();

val = (val << 8) + (c & 0xFF);
}

val = val / 1.2;
emitValue<output_Light>(ctx, val);
emitValue<output_DONE>(ctx, 1);

delay(100);
    }
}