KRITSADA

Sony IR Remote Control With MakeCode

Aug 23rd, 2018
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let IR2 = 0
  2. let index = 0
  3. let A: number[] = []
  4. let Flag = 0
  5. let value = 0
  6. pins.onPulsed(DigitalPin.P0, PulseValue.Low, () => {
  7.     if (pins.pulseDuration() > 2000) {
  8.         Flag = 1
  9.     }
  10.     if (A.length <= 14 && Flag == 1) {
  11.         A.push(pins.pulseDuration())
  12.     }
  13.     if (A.length == 14) {
  14.         serial.writeValue("Length", A.length)
  15.         index = 0
  16.         IR2 = 0
  17.         for (let value2 of A) {
  18.             if (value2 > 1000) {
  19.                 IR2 = IR2 + 2 ** index
  20.             } else {
  21.                 IR2 = IR2 + 0
  22.             }
  23.             index += 1
  24.         }
  25.         serial.writeValue("IR", IR2)
  26.         A = []
  27.         Flag = 0
  28.     }
  29. })
  30. value = 0
  31. pins.setPull(DigitalPin.P0, PinPullMode.PullUp)
  32. A = []
  33. serial.redirectToUSB()
Advertisement
Add Comment
Please, Sign In to add comment