KRITSADA

Ibit Line Tracing and Check Sensor from P1 and P2

Sep 19th, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let R = 0
  2. let L = 0
  3. let RefR = 0
  4. let RefL = 0
  5. function adc1()  {
  6.     basic.showNumber(pins.analogReadPin(AnalogPin.P1))
  7. }
  8. input.onButtonPressed(Button.A, () => {
  9.     adc1()
  10. })
  11. function adc2()  {
  12.     basic.showNumber(pins.analogReadPin(AnalogPin.P2))
  13. }
  14. input.onButtonPressed(Button.B, () => {
  15.     adc2()
  16. })
  17. function Run()  {
  18.     while (true) {
  19.         L = pins.analogReadPin(AnalogPin.P1)
  20.         R = pins.analogReadPin(AnalogPin.P2)
  21.         if (L > RefL && R > RefR) {
  22.             iBIT.Motor(ibitMotor.Forward, 100)
  23.         } else if (L < RefL && R > RefR) {
  24.             iBIT.setMotor(ibitMotorCH.M1, ibitMotor.Forward, 20)
  25.             iBIT.setMotor(ibitMotorCH.M2, ibitMotor.Forward, 80)
  26.         } else if (L > RefL && R < RefR) {
  27.             iBIT.setMotor(ibitMotorCH.M1, ibitMotor.Forward, 80)
  28.             iBIT.setMotor(ibitMotorCH.M2, ibitMotor.Forward, 20)
  29.         }
  30.     }
  31. }
  32. input.onButtonPressed(Button.AB, () => {
  33.     Run()
  34. })
  35. RefL = 150
  36. RefR = 120
Advertisement
Add Comment
Please, Sign In to add comment