![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code for testing scooter electronics
Dependencies: mbed BH1750 BLE_API L3GD20H nRF51822
main.cpp
- Committer:
- wonin
- Date:
- 2022-02-15
- Revision:
- 0:3cef86fc978f
- Child:
- 1:aa9eabdefc12
File content as of revision 0:3cef86fc978f:
#include "mbed.h" #include "BH1750.h" // I2C Communication BH1750 lum(P0_30,P0_7); // BH1750 SDA, SCL Serial pc(USBTX, USBRX); // tx, rx DigitalOut led(LED2); int tickerCntr1 = 0; Ticker flipLed; float dutyCycle=1.0f; DigitalOut BH1750_EN0(P0_13); float lum0 = 0; //DigitalOut BH1750_EN1(P0_14); //float lum1 = 0; // // If you connected I2C line not only this device but also other devices, // // you need to declare following method. // I2C i2c(P0_7,P0_30); // SDA, SCL // BH1750 lum(i2c); // BH1750 SDA, SCL (Data available every 120mSec) void flip(){ // if(tickerCntr1 %3000 == 0) // dutyCycle -= 0.01; // // if(dutyCycle<= 0) // dutyCycle = 1; if(dutyCycle<= 0) dutyCycle = 0; else if(dutyCycle >= 1) dutyCycle = 1; if(100*dutyCycle >= tickerCntr1%100){ led = 1; } else{ led = 0; } tickerCntr1++; if(tickerCntr1 ==100001 ) tickerCntr1 = 0; } void measureBH1750_0(){ BH1750_EN0 = 0; BH1750_EN1 = 1; //wait(0.005); return lum.lux(); } float measureBH1750_1(){ BH1750_EN0 = 1; BH1750_EN1 = 0; // wait(0.005); return lum.lux(); } int main() {; int reading_num = 0; flipLed.attach_us(&flip, 50.0f); while(true){ // lum1 = measureBH1750_1(); // lum0 = measureBH1750_0(); // pc.printf("Illuminance 1: %+7.2f [Lux] : Illuminance 2: %+7.2f [Lux] : %i\r\n", lum0, lum1, reading_num++); wait(0.5); } }