def on_button2_callback(): global rage, t if rage > random.randint(3, 5): rage = 0 time.sleep(0.5) codey.display.show_image('00003c1e0e0400000000040e1e3c0000') rocky.backward(20, 0.4) rocky.backward(100, 0.01) rocky.forward(100, 0.2) rocky.backward(100, 0.01) time.sleep(0.1) codey.speaker.play_melody('angry.wav') time.sleep(0.5) codey.display.show_image('00003c7e7e3c000000003c7e7e3c0000') else: time.sleep(0.5) codey.display.show_image('00081c3c3c3820000020383c3c1c0800') time.sleep(0.5) codey.speaker.play_melody('sad.wav') codey.display.show_image('00040e1e1e1c100000101c1e1e0e0400') rocky.backward(50, 0.1) codey.display.show_image('00081c3c3c3820000020383c3c1c0800') time.sleep(0.3) codey.display.show_image('00183c3c7c7820000020787c3c3c1800') time.sleep(0.1) codey.display.show_image('00003c7e7e3c000000003c7e7e3c0000') rage = (rage if isinstance(rage, int) or isinstance(rage, float) else 0) + 2
def on_button1_callback(): global rage, t if rage > random.randint(3, 5): rage = 0 time.sleep(0.5) codey.display.show_image('00003c1e0e0400000000040e1e3c0000') rocky.backward(20, 0.4) rocky.backward(100, 0.01) rocky.forward(100, 0.2) rocky.backward(100, 0.01) time.sleep(0.1) codey.speaker.play_melody('angry.wav') time.sleep(0.5) codey.display.show_image('00003c7e7e3c000000003c7e7e3c0000') else: time.sleep(0.4) codey.display.show_image('000c18181c0c000000000c1c18180c00') codey.speaker.play_melody('laugh.wav') rocky.turn_right(70, 0.05) codey.display.show_image('00183030381800000000183830301800') rocky.turn_left(70, 0.05) codey.display.show_image('000c18181c0c000000000c1c18180c00') rocky.turn_right(70, 0.05) rocky.turn_left(70, 0.05) time.sleep(0.3) codey.display.show_image('00183030381800000000183830301800') time.sleep(0.1) codey.display.show_image('00003c7e7e3c000000003c7e7e3c0000') rage = (rage if isinstance(rage, int) or isinstance(rage, float) else 0) + 1
def on_start(): codey.emotion.wake_up() codey.emotion.look_around() codey.display.show('hello', wait=False) codey.speaker.play_melody('hello.wav') rocky.forward(25, 1) codey.display.show_image("000c1010100c000000000c1010100c00")
def on_button_callback(): rocky.forward(50, 0.5) rocky.forward(50, 0.5) rocky.forward(50, 0.5) rocky.turn_right_angle(90) rocky.forward(50, 0.5) rocky.forward(50, 0.5) codey.face('00001020402012020212204020100000', 0.5) codey.say('cat.wav')
def car_forward_test(): print("Forward using forward") for speed in list(range(0, 101, 20)): print("Forward speed: %d" % speed) rocky.forward(speed, 1) for speed in list(range(0, 101, 20)): print("Forward speed: %d" % -speed) rocky.forward(-speed, 1)
def on_button_a_pressed(): codey.speaker.play_melody('hello.wav') while True: rocky.forward(50) if rocky.color_ir_sensor.is_obstacle_ahead(): codey.speaker.play_melody('wrong.wav', True) rocky.backward(50, 1, straight=True) rocky.turn_left_by_degree(90) rocky.forward(50, 2, straight=True)
def rocky_send(): print("rocky forward") rocky.forward(100, 2) print("rocky back") rocky.back(100, 2) print("rocky left") rocky.left(100, 2) print("rocky right") rocky.right(100, 2) print("rocky stop")
def on_start(): codey.display.show('hello', wait=False) codey.display.show_image("00003c1e0e0400000000040e1e3c0000", time_s=1) codey.display.show_image("00003c7e7e3c000000003c7e7e3c0000", time_s=1) codey.display.clear() codey.led.show(255, 0, 0, 1) codey.speaker.play_melody('hi.wav') codey.speaker.play_melody('wow.wav') rocky.forward(50, 1) rocky.turn_left(50, 1) rocky.forward(50, 1, straight=True)
def rocky_send(): print("rocky forward") rocky.forward(100, 2) print("rocky back") rocky.backward(100, 2) print("rocky left") rocky.turn_left(100, 2) print("rocky right") rocky.turn_right(100, 2) print("rocky stop") print("rocky set rgb color white") rocky.color("#ffffff") time.sleep(1) print("rocky set rgb color red") rocky.color("#ff0000")
def rocky_read(): print("rocky color is:", rocky.get_color()) # not a demand print("red value is:", rocky.red()) print("green value is:", rocky.green()) print("blue value is:", rocky.blue()) print("rocky grey is:", rocky.grey()) print("rocky obstacle is:", rocky.is_obstacle_ahead()) print("rocky light is:", rocky.light_strength()) print("rocky light reflect is:", rocky.reflection_strength()) print("rocky ir reflect is:", rocky.ir_reflection_strength()) print("rocky left motor current is ", rocky.motor_current('left')) rocky.forward(100) time.sleep(1) print("rocky left motor current is ", rocky.motor_current('left')) rocky.stop() print("")
def on_button_a_pressed(): rocky.forward(50, 1) rocky.turn_right_by_degree(94) rocky.forward(50, 1) rocky.turn_right_by_degree(94) rocky.forward(50, 1) rocky.turn_right_by_degree(94) rocky.forward(50, 1) codey.emotion.yeah()
def on_button1_callback(): global angerValue if angerValue > random.randint(3, 5): angerValue = 0 time.sleep(0.2) codey.face('00003c1e0e0400000000040e1e3c0000') rocky.back(50) time.sleep(0.4) codey.say('dog.wav') codey.face('00007c3e1e0e040000040e1e3e7c0000') rocky.back(100) time.sleep(0.05) rocky.forward(100) time.sleep(0.5) rocky.back(100) time.sleep(0.01) rocky.stop() time.sleep(0.2) else: codey.say('happy.wav') codey.face('000c18181c0c000000000c1c18180c00') time.sleep(0.3) rocky.left(70) time.sleep(0.05) codey.face('00183030381800000000183830301800') rocky.right(70) time.sleep(0.05) rocky.left(70) time.sleep(0.05) rocky.right(70) time.sleep(0.05) rocky.stop() codey.face('000c18181c0c000000000c1c18180c00') time.sleep(0.3) codey.face('00183030381800000000183830301800') time.sleep(0.1) codey.face('00003c7e7e3c000000003c7e7e3c0000') angerValue = (angerValue if isinstance(angerValue, int) or isinstance(angerValue, float) else 0) + 1 codey.message(str('hello'))
def on_button_callback(): global angerValue if angerValue > random.randint(3, 5): angerValue = 0 time.sleep(0.2) codey.face('00003c1e0e0400000000040e1e3c0000') rocky.back(50) time.sleep(0.4) codey.say('dog.wav') codey.face('00007c3e1e0e040000040e1e3e7c0000') rocky.back(100) time.sleep(0.05) rocky.forward(100) time.sleep(0.5) rocky.back(100) time.sleep(0.01) rocky.stop() time.sleep(0.2) else: codey.say('wrong.wav') codey.face('00081c1c3c3820000020383c1c1c0800') time.sleep(0.3) rocky.back(20) codey.face('00040e0e1e1c100000101c1e0e0e0400') rocky.back(50) time.sleep(0.1) codey.face('00081c1c3c3820000020383c1c1c0800') rocky.stop() time.sleep(0.3) codey.face('00183c3c7c7820000020787c3c3c1800') time.sleep(0.1) codey.face('00003c7e7e3c000000003c7e7e3c0000') angerValue = (angerValue if isinstance(angerValue, int) or isinstance(angerValue, float) else 0) + 1 codey.message(str('hello'))
codey.is_button('A') codey.is_shaked() codey.is_tilt('forward') codey.sound_strength() codey.light_strength() codey.dail() codey.gyro('pitch') codey.time() codey.reset_time() codey.ir_send("A") codey.ir_receive() print("***codey APIS all succeed***") # about rocky rocky.color("#334455") rocky.forward(50, 1) rocky.backward(50, 1) rocky.turn_left(50, 1) rocky.turn_right(50, ) rocky.forward(50) rocky.backward(50) rocky.turn_left(50) rocky.turn_right(50) rocky.drive(50, 50) rocky.turn_left_angle(15) rocky.turn_right_angle(15) rocky.stop() rocky.is_obstacle_ahead() rocky.is_color('red') rocky.red()
import codey import rocky import time import event rocky.forward(20) time.sleep(1) rocky.forward(-20) time.sleep(1) rocky.backward(-20) time.sleep(1) rocky.backward(20) time.sleep(1) rocky.turn_left(20) time.sleep(1) rocky.turn_left(-20) time.sleep(1) rocky.turn_right(-20) time.sleep(1) rocky.turn_right(20) time.sleep(1) rocky.forward(20, 1) rocky.forward(-20, 1) rocky.backward(-20, 1) rocky.backward(20, 1) rocky.turn_left(20, 1) rocky.turn_left(-20, 1) rocky.turn_right(-20, 1) rocky.turn_right(20, 1)