Ejemplo n.º 1
0
def show_animation(frame_speed, mode, index = 1):
    if type_check(frame_speed, int, float) and type_check(mode, int, float):
        frame_speed = int(num_range_check(frame_speed, 0, 2))
        mode = int(num_range_check(mode, 0, 3))

        neurons_engine_o.send(LEDMATRIX_TYPE, LEDMATRIX_SUBTYPE, [LEDMATRIX_SHOW_ANIMATION, \
                              frame_speed, mode], int(index))
Ejemplo n.º 2
0
def backward(speed, t = None, straight = False, index = 1):
    if type_check(speed, int, float) and type_check(straight, bool) and type_check(index, int, float) and (type_check(t, int, float) or t == None):
        if type_check(t, int, float):
           if t <= 0:
               return
        speed = num_range_check(speed, -100, 100)

        if(straight == False):
            rocky_straight_move_o.set_rocky_straight_move_flag(False);
            if speed < 0:
                # neu.neu_send("ROCKY","forward", [-speed], int(index))
                neurons_engine_o.send(ROCKY_TYPE, ROCKY_SUBTYPE, [FUNC_FORWARD, -speed], int(index))
            else:
                # neu.neu_send("ROCKY","back", [speed], int(index))
                neurons_engine_o.send(ROCKY_TYPE, ROCKY_SUBTYPE, [FUNC_BACKWARD, speed], int(index))
        else:
            if(speed == 0):
                rocky_straight_move_o.set_rocky_straight_move_flag(False);
                rocky_straight_move_o.set_rocky_target_speed(0);
            else:
                rocky_straight_move_o.set_rocky_target_speed(-speed);
                rocky_straight_move_o.init_rocky_angle();
                rocky_straight_move_o.set_rocky_straight_move_flag(True);
        if t != None:
            time.sleep(t)
            stop()
            if (straight == True):
                rocky_straight_move_o.set_rocky_straight_move_flag(False);
Ejemplo n.º 3
0
def set_all(red_value, green_value, blue_value, index = 1):
    if type_check(red_value, int, float) and type_check(green_value, int, float) \
       and type_check(blue_value, int, float):
        red_value = int(num_range_check(red_value, 0, 255))
        green_value = int(num_range_check(green_value, 0, 255))
        blue_value = int(num_range_check(blue_value, 0, 255))
        neurons_engine_o.send(RGB_SCRIPT_TYPE, RGB_SCRIP_SUBTYPE, [RGB_SCRIP_SET, 0, red_value, green_value, blue_value], int(index))
Ejemplo n.º 4
0
def set_all(red_value, green_value, blue_value, index = 1):
    if type_check(red_value, int, float) and \
       type_check(green_value, int, float) and type_check(blue_value, int, float):
        red_value = int(num_range_check(red_value, 0, 255))
        green_value = int(num_range_check(green_value, 0, 255))
        blue_value = int(num_range_check(blue_value, 0, 255))
        neurons_engine_o.send(LEDMATRIX_TYPE, LEDMATRIX_SUBTYPE, [LEDMATRIX_SET_SINGLE, \
                              0, red_value, green_value, blue_value], int(index))
Ejemplo n.º 5
0
def set_single(led_id, red_value, green_value, blue_value, index = 1):
    if type_check(led_id, int, float) and type_check(red_value, int, float) and \
       type_check(green_value, int, float) and type_check(blue_value, int, float):
        led_id = int(num_range_check(led_id, 1, 127))
        red_value = int(num_range_check(red_value, 0, 255))
        green_value = int(num_range_check(green_value, 0, 255))
        blue_value = int(num_range_check(blue_value, 0, 255))

        neurons_engine_o.send(RGB_SCRIPT_TYPE, RGB_SCRIP_SUBTYPE, [RGB_SCRIP_SET, led_id, red_value, green_value, blue_value], int(index))
Ejemplo n.º 6
0
def set_angle(position, ch=0, index=1):
    if type_check(ch, int, float) and type_check(position, int, float):
        ch = num_range_check(ch, 0, 2)
        position = num_range_check(position, 0, 180)
        if ch == 0:
            neurons_engine_o.send(SERVO_TYPE, SERVO_SUBTYPE,
                                  [ch + 1, position, position], int(index))
        else:
            neurons_engine_o.send(SERVO_TYPE, SERVO_SUBTYPE,
                                  [ch + 1, position], int(index))
Ejemplo n.º 7
0
def set_power(speed, ch=0, index=1):
    if type_check(ch, int, float) and type_check(speed, int, float):
        ch = num_range_check(ch, 0, 2)
        speed = num_range_check(speed, -100, 100)
        if ch == 0:
            neurons_engine_o.send(DMOTOR_TYPE, DMOTOR_SUBTYPE,
                                  [ch + 1, speed, speed], int(index))
        else:
            neurons_engine_o.send(DMOTOR_TYPE, DMOTOR_SUBTYPE, [ch + 1, speed],
                                  int(index))
Ejemplo n.º 8
0
def show_string(red_value, green_value, blue_value, data, index = 1):
    if type_check(red_value, int, float) and type_check(green_value, int, float) \
       and type_check(blue_value, int, float):
        data = str(data)
        red_value = int(num_range_check(red_value, 0, 255))
        green_value = int(num_range_check(green_value, 0, 255))
        blue_value = int(num_range_check(blue_value, 0, 255))
        char_num = len(data)
        data = list(map(ord, list(data)))
        neurons_engine_o.send(LEDMATRIX_TYPE, LEDMATRIX_SUBTYPE, [LEDMATRIX_SHOW_STRING, \
                              red_value, green_value, blue_value, char_num] + data, int(index))
Ejemplo n.º 9
0
def set_pixel(pos_x, pos_y, red_value, green_value, blue_value, index = 1):
    if type_check(pos_x, int, float) and type_check(pos_y, int, float) and type_check(red_value, int, float) and \
       type_check(green_value, int, float) and type_check(blue_value, int, float):
        if pos_x > 7 or pos_x < 0 or pos_y > 7 or pos_y < 0:
            return
        red_value = int(num_range_check(red_value, 0, 255))
        green_value = int(num_range_check(green_value, 0, 255))
        blue_value = int(num_range_check(blue_value, 0, 255))
        led_id = pos_y * 8 + pos_x + 1
        neurons_engine_o.send(LEDMATRIX_TYPE, LEDMATRIX_SUBTYPE, [LEDMATRIX_SET_SINGLE, \
                              led_id, red_value, green_value, blue_value], int(index))
Ejemplo n.º 10
0
def turn_right(speed, t = None, index = 1):
    if type_check(speed, int, float) and type_check(index, int, float) and (type_check(t, int, float) or t == None):
        if type_check(t, int, float):
           if t <= 0:
               return
        speed = int(num_range_check(speed, -100, 100))
        if speed < 0:
            # neu.neu_send("ROCKY", "left", [-speed], int(index))
            neurons_engine_o.send(ROCKY_TYPE, ROCKY_SUBTYPE, [FUNC_LEFT, -speed], int(index))
        else:
            # neu.neu_send("ROCKY","right", [speed], int(index))
            neurons_engine_o.send(ROCKY_TYPE, ROCKY_SUBTYPE, [FUNC_RIGHT, speed], int(index))
        if t != None:
            time.sleep(t)
            stop()
Ejemplo n.º 11
0
def set_effect(mode, change_speed, data, index = 1):
    # add parameters checking here
    if type_check(mode, int, float) and type_check(change_speed, int, float)\
       and type_check(data, list, tuple):

        mode = int(num_range_check(mode, 0, 5))
        change_speed = int(num_range_check(change_speed, 0, 8))
        data = list(data)
        for i in range(len(data)):
            if type(data[i]) == str:
                if data[i] in color_dict:
                    data[i] = color_dict[i]

        neurons_engine_o.send(RGB_SCRIPT_TYPE, RGB_SCRIP_SUBTYPE, [RGB_SCRIP_SET_MODE, mode, change_speed, len(data)] + list(data), int(index))

# clear() --- rgb_strip.set_mode(0, 0, 16, [])
Ejemplo n.º 12
0
def drive(left_power, right_power, index = 1): # not support now
    if (not type_check(left_power, int, float)) or (not type_check(right_power, int, float)):
        return
    if left_power < 0:
        left_dir = 1
        left_power = -left_power
    else:
        left_dir = 0

    if right_power < 0:
        right_dir = 0
        right_power = -right_power
    else:
        right_dir = 1
    left_power = num_range_check(left_power, -100, 100)
    right_power = num_range_check(right_power, -100, 100)    
    # neu.neu_send("ROCKY","drive", [left_dir, left_power, right_dir, right_power], int(index))
    neurons_engine_o.send(ROCKY_TYPE, ROCKY_SUBTYPE, [FUNC_DRIVE, left_dir, left_power, right_dir, right_power], int(index))
Ejemplo n.º 13
0
 def set_led_color(self, color_name, index = 1):
     dict = {"red":[1,0,0], "green":[0,1,0], "blue":[0,0,1],\
             "yellow":[1,1,0], "purple":[1,0,1], "cyan":[0,1,1],\
             "white":[1,1,1], "black":[0,0,0]
             }
     if not type_check(color_name, str):
         return
     if color_name in dict:
         val = dict[color_name]
         # neu.neu_send("ROCKY", "set_rgb", val, int(index)) 
         ret = neurons_engine_o.send(ROCKY_TYPE, ROCKY_SUBTYPE, [FUNC_SET_COLOR] + val, int(index)) 
Ejemplo n.º 14
0
    def play_note(self, note, beat=None, index=1):
        if (not type_check(beat, int, float)) and beat != None:
            return
        if beat != None:
            if beat <= 0:
                self.__off()
                return

        if type_check(note, int, float):
            if note <= 0:
                return
            note = num_range_check(note, 0, 127)

            freq = MIDI_NOTE_NUM0 * math.pow(NOTE_FREQUENCE_RATIO, note)

        elif type_check(note, str):
            if note in node_table:
                freq = node_table[note]
            else:
                print_dbg("not found the node", note)
                return

        if beat == None:
            neurons_engine_o.send(BUZZER_TYPE, BUZZER_SUBTYPE,
                                  [BUZZER_PLAY, freq, 50], int(index))
        else:
            neurons_engine_o.send(BUZZER_TYPE, BUZZER_SUBTYPE,
                                  [BUZZER_PLAY, freq, 50], int(index))
            time.sleep(beat * (60 / self.note_tempo))
            neurons_engine_o.send(BUZZER_TYPE, BUZZER_SUBTYPE,
                                  [BUZZER_PLAY, 0, 0], int(index))
Ejemplo n.º 15
0
    def play_tone(self, frequency, beat=None, index=1, duty=50):
        if type_check(frequency, int, float) and (beat == None or type_check(
                beat, int, float)):
            if frequency <= 0:
                self.__off()
                return
            if beat != None:
                if beat <= 0:
                    self.__off()
                    return

        frequency = num_range_check(frequency, 0, 5000)
        if beat == None:
            neurons_engine_o.send(BUZZER_TYPE, BUZZER_SUBTYPE,
                                  [BUZZER_PLAY, frequency, duty], int(index))
        else:
            neurons_engine_o.send(BUZZER_TYPE, BUZZER_SUBTYPE,
                                  [BUZZER_PLAY, frequency, duty], int(index))
            time.sleep(beat * (60 / self.note_tempo))
            neurons_engine_o.send(BUZZER_TYPE, BUZZER_SUBTYPE,
                                  [BUZZER_PLAY, 0, 0], int(index))
Ejemplo n.º 16
0
def show_image(image_code, mode = 0, index = 1):
    if type_check(mode, int, float) and type_check(image_code, list, tuple):
        mode = int(num_range_check(mode, 0, 3))

        neurons_engine_o.send(LEDMATRIX_TYPE, LEDMATRIX_SUBTYPE, [LEDMATRIX_SET_PANEL, \
                              mode, len(image_code)] + list(image_code), int(index))
Ejemplo n.º 17
0
def set_animation(frame_index, data, index = 1):
    if type_check(frame_index, int, float) and type_check(data, list, tuple):
        frame_index = int(num_range_check(frame_index, 0, 3))

        neurons_engine_o.send(LEDMATRIX_TYPE, LEDMATRIX_SUBTYPE, [LEDMATRIX_SET_ANIMATION, \
                              frame_index, len(data)] + list(data), int(index))
Ejemplo n.º 18
0
def clear(index = 1):
    neurons_engine_o.send(LEDMATRIX_TYPE, LEDMATRIX_SUBTYPE, [LEDMATRIX_SET_SINGLE, \
                          0, 0, 0, 0], int(index))
Ejemplo n.º 19
0
def stop(index = 1):
    global rocky_stop_flag
    rocky_stop_flag = True
    rocky_straight_move_o.set_rocky_straight_move_flag(False);
    rocky_straight_move_o.set_rocky_target_speed(0);
    neurons_engine_o.send(ROCKY_TYPE, ROCKY_SUBTYPE, [FUNC_FORWARD, 0], int(index))
Ejemplo n.º 20
0
 def __off(self, index=1):
     neurons_engine_o.send(BUZZER_TYPE, BUZZER_SUBTYPE, [BUZZER_PLAY, 0, 0],
                           int(index))