|
Example 4: The left motor first runs for 3 seconds at a speed of 50 forwards, then 2 seconds at a speed of 30 backwards. It then stops. First run the programme in simulation mode and observe the rotations in the graphics window.
from mbrobot import *
#from mbrobot_plusV2 import *
motL.rotate(50)
delay(3000)
motL.rotate(-30)
delay(2000)
motL.rotate(0)
►Copy to clipboard |
|
|
Example 5: Switch leds on and off individually
You can use the setLED(1) and setLED(0) commands to switch both LEDs on and off at the same time. You can also address the LEDs individually:
Your programme switches one LED on and the other off.
|
|
|
You use the following commands:
setLEDLeft(1) switches on the left LED
setLEDLeft(0) switches off the left LED
setLEDRight(1) switches on the right LED
setLEDRight(0) switches off the right LED
from mbrobot import *
from mbrobot_plusV2 import *
setLEDLeft(1)
setLEDRight(0)
delay(600)
setLEDLeft(0)
setLEDRight(1)
delay(600)
setLEDLeft(1)
setLEDRight(0)
delay(600)
setLEDLeft(0)
setLEDRight(1)
delay(600)
setLEDRight(0)
►Copy to clipboard
Example 6: RGB LEDs (nur Maqueen Plus V2)
Maqueen Plus V2 has four RGB LEDs on the bottom of the robot. You can use the setRGB(id, r, g, b)command to make them light up in different colors, where id is the number of the LED, r is the red, g is the green and b is the blue color component. clearRGB() switches off all LEDs.
In your program, the first LED is switched on red, the second green, the third blue and the fourth violet in sequence. Then all 4 are switched off.
|
|
|
from mbrobot_plusV2 import *
repeat 3:
setRGB(0, 255, 0, 0)
delay(1000)
setRGB(1, 0, 255, 0)
delay(1000)
setRGB(2, 0, 0, 255)
delay(1000)
setRGB(3, 255, 0, 255)
delay(1000)
clearRGB()
►Copy to clipboard |