#!/usr/bin/env python3
from ev3dev2.motor import MediumMotor,OUTPUT_A,SpeedPercent
from ev3dev2.sensor import INPUT_1
from ev3dev2.sensor.lego import TouchSensor
from ev3dev2.led import Leds
from ev3dev.ev3 import Sound
import time
import random
 
m = MediumMotor(OUTPUT_A)
ts = TouchSensor()
leds = Leds()
 
hlasky = ["Fire","You only live once", "Prepare to hit","Fire in a hole"]
Sound.speak("EV3 gun at your command").wait()
 
while True:
  if ts.is_pressed:
    Sound.speak(random.choice(hlasky)).wait()
    leds.set_color("LEFT","ORANGE")
    leds.set_color("RIGHT","RED")
    m.on_for_rotations(SpeedPercent(100),3)
  else:
    leds.set_color("LEFT","GREEN")
    leds.set_color("RIGHT","ORANGE")

Síla podle doby stisku tlačítka:

#!/usr/bin/env python3
from ev3dev2.motor import MediumMotor,OUTPUT_A,SpeedPercent
from ev3dev2.sensor import INPUT_1
from ev3dev2.sensor.lego import TouchSensor
from ev3dev2.led import Leds
from ev3dev.ev3 import Sound
import time
import random
 
m = MediumMotor(OUTPUT_A)
ts = TouchSensor()
leds = Leds()
 
hlasky = ["Fire","You only live once", "Prepare to hit","Fire in a hole"]
Sound.speak("EV3 gun at your command").wait()
 
while True:
  if ts.is_pressed:
    #base strength
    strength = 25
    while strength < 100 and ts.is_pressed:
      strength+=1
      time.sleep(0.05)
 
    Sound.speak(random.choice(hlasky)).wait()
    Sound.speak(" at "+str(strength)+" percent").wait()
    leds.set_color("LEFT","ORANGE")
    leds.set_color("RIGHT","RED")
    m.on_for_rotations(SpeedPercent(strength),3)
  else:
    leds.set_color("LEFT","GREEN")
    leds.set_color("RIGHT","ORANGE")