Introduction
You might have already played with your new Robit Smart Car and got it to move, avoid obstacles, and even avoid falling off platforms.
In this guide, you will next learn to use the light sensor on the Robit Smart Car. With the light sensor, the Robit will be transformed into a light-seeking robot! It can also be programmed to turn its LEDs on or off depending on light.
Complete this guide to add more function to your robot car buddy!
-
-
-
let lightVal = 0 basic.forever(function () { lightVal = pins.analogReadPin(AnalogPin.P10) if (lightVal < 500) { neopixel.create(DigitalPin.P12, 2, NeoPixelMode.RGB).showColor(neopixel.colors(NeoPixelColors.White)) basic.pause(3000) } else { neopixel.create(DigitalPin.P12, 2, NeoPixelMode.RGB).showColor(neopixel.colors(NeoPixelColors.Black)) } })
-
let threshold = 0 let lightVal = 0 lightVal = 0 robit.MotorRunDual( robit.Motors.M1, 50, robit.Motors.M2, 50 ) basic.forever(function () { threshold = 800 lightVal = pins.analogReadPin(AnalogPin.P10) if (lightVal < threshold) { robit.MotorRunDual( robit.Motors.M1, 50, robit.Motors.M2, 50 ) } else { robit.MotorStopAll() neopixel.create(DigitalPin.P12, 2, NeoPixelMode.RGBW).showColor(neopixel.colors(NeoPixelColors.Red)) } })
-
let dist = 0 let threshold = 0 let lightVal = 0 lightVal = 0 dist = 0 robit.MotorRunDual( robit.Motors.M1, 50, robit.Motors.M2, 50 ) basic.forever(function () { threshold = 800 lightVal = pins.analogReadPin(AnalogPin.P10) dist = robit.Ultrasonic(robit.Jpin.J1) if (dist > 5 && lightVal < threshold) { robit.MotorRunDual( robit.Motors.M1, 50, robit.Motors.M2, 50 ) } else if (dist < 5 && lightVal < threshold) { robit.MotorRunDual( robit.Motors.M1, -50, robit.Motors.M2, -50 ) if (Math.randomRange(0, 100) < 50) { robit.MotorRun(robit.Motors.M1, -25) basic.pause(500) } else { robit.MotorRun(robit.Motors.M1, -25) basic.pause(500) } } else { robit.MotorStopAll() neopixel.create(DigitalPin.P12, 2, NeoPixelMode.RGBW).showColor(neopixel.colors(NeoPixelColors.Red)) } })
-