|
1 | 1 | // When this software package is used as a plugin, this package will not be compiled.
|
2 | 2 |
|
| 3 | +input.onButtonPressed(Button.A, function () { |
| 4 | + testMode += 1 |
| 5 | + if (testMode > 4) { |
| 6 | + testMode = 1 |
| 7 | + } |
| 8 | +}) |
| 9 | +function testMotor() { |
| 10 | + robotics.motorRun(robotics.MotorType.M1, robotics.MotorDirection.CW, 100) |
| 11 | + robotics.motorRun(robotics.MotorType.M2, robotics.MotorDirection.CCW, 100) |
| 12 | + basic.pause(1000) |
| 13 | + robotics.motorRun(robotics.MotorType.All, robotics.MotorDirection.CW, 150) |
| 14 | + basic.pause(1000) |
| 15 | + robotics.motorRun(robotics.MotorType.All, robotics.MotorDirection.CCW, 150) |
| 16 | + basic.pause(1000) |
| 17 | + robotics.motorStop(robotics.MotorType.M1) |
| 18 | +} |
| 19 | +function testSensor() { |
| 20 | + serial.writeLine("PIN P0 --> distance: " + robotics.readUltrasonicData(robotics.CustomAllPin.P0) + "cm") |
| 21 | + serial.writeLine("PIN P1 --> soil moisture: " + robotics.readMoistureData(robotics.CustomAnalogPin.P1)) |
| 22 | + serial.writeLine("PIN P2 --> ambient light: " + robotics.readLightData(robotics.CustomAnalogPin.P2)) |
| 23 | + serial.writeLine("PIN P8 --> tracker state: " + robotics.readLineTrackingData(robotics.CustomAllPin.P8)) |
| 24 | + serial.writeLine("PIN P9 -->temperature: " + robotics.readDht11Data(robotics.CustomAllPin.P9, robotics.DataType.TemperatureC)) |
| 25 | + serial.writeLine("PIN P9 --> humidity: " + robotics.readDht11Data(robotics.CustomAllPin.P9, robotics.DataType.Humidity)) |
| 26 | + serial.writeLine("PIN P12 --> infrared motion: " + robotics.readInfraredData(robotics.CustomAllPin.P12)) |
| 27 | + serial.writeLine("-------------------------------------------------") |
| 28 | +} |
| 29 | +function testRgbLight() { |
| 30 | + robotics.ws2812Init(robotics.CustomAllPin.P14, 7) |
| 31 | + robotics.ws2812SBrightness(50) |
| 32 | + robotics.ws2812SetIndexColor(1, 0x007fff) |
| 33 | + robotics.ws2812SetIndexColor(robotics.ws2812LedRange(2, 7), 0xff0000) |
| 34 | + basic.pause(1000) |
| 35 | + robotics.ws2812Off() |
| 36 | + robotics.ws2812Rainbow(1, 7, 1, 360) |
| 37 | + for (let index = 0; index < 7; index++) { |
| 38 | + basic.pause(1000) |
| 39 | + robotics.ws2812Shift(1) |
| 40 | + } |
| 41 | + robotics.ws2812Rainbow(1, 7, 1, 360) |
| 42 | + for (let index = 0; index < 7; index++) { |
| 43 | + basic.pause(1000) |
| 44 | + robotics.ws2812Rotate(1) |
| 45 | + } |
| 46 | +} |
| 47 | +function testServo() { |
| 48 | + robotics.servoRun180(robotics.CustomAllPin.P16, 0) |
| 49 | + basic.pause(1000) |
| 50 | + robotics.servoRun180(robotics.CustomAllPin.P16, 90) |
| 51 | + basic.pause(1000) |
| 52 | + robotics.servoRun180(robotics.CustomAllPin.P16, 180) |
| 53 | + basic.pause(1000) |
| 54 | + robotics.servoRun360(robotics.CustomAllPin.P15, 50, robotics.MotorDirection.CW) |
| 55 | + basic.pause(1000) |
| 56 | + robotics.servoRun360(robotics.CustomAllPin.P15, 50, robotics.MotorDirection.CCW) |
| 57 | + basic.pause(1000) |
| 58 | + robotics.servoRun360(robotics.CustomAllPin.P15, 0, robotics.MotorDirection.CCW) |
| 59 | +} |
| 60 | +let testMode = 0 |
| 61 | +testMode = 0 |
| 62 | +basic.forever(function () { |
| 63 | + serial.writeString("mode:" + testMode) |
| 64 | + if (testMode == 1) { |
| 65 | + serial.writeLine(" Servo PIN: 180-->P16 360-->P15") |
| 66 | + testServo() |
| 67 | + basic.pause(1000) |
| 68 | + } else if (testMode == 2) { |
| 69 | + serial.writeLine(" Motor M1 M2") |
| 70 | + testMotor() |
| 71 | + basic.pause(1000) |
| 72 | + } else if (testMode == 3) { |
| 73 | + serial.writeLine(" RGB PIN: P14") |
| 74 | + testRgbLight() |
| 75 | + basic.pause(1000) |
| 76 | + } else if (testMode == 4) { |
| 77 | + serial.writeLine(" Sensor Note: Note: P9 pin must be connected to DHT11 sensor") |
| 78 | + testSensor() |
| 79 | + basic.pause(1000) |
| 80 | + } else { |
| 81 | + serial.writeLine("") |
| 82 | + serial.writeLine("Press the A key to select the mode") |
| 83 | + basic.pause(1000) |
| 84 | + } |
| 85 | +}) |
0 commit comments