void glLightSwitch::turn_off( ) { if (m_on_is_up) turn_down(); else turn_up(); }
void glLightSwitch::toggle( ) { if (m_position_is_up) turn_down(); else turn_up(); }
int launcher(t_box *box) { char buf[1]; int dir; jump; ft_putstr("\033[35mWHICH DIRECTION FOR THE NEXT MOVE ? :\033[0m"); jump; while (read(0, buf, sizeof(buf))) { if (!(dir = check(buf))) continue ; if (dir == 2) turn_right(box); if (dir == 1) turn_left(box); if (dir == 3) turn_up(box); if (dir == 4) turn_down(box); ft_putstr("YOUR SCORE IS : "); ft_putnbr(box->score); jump; jump; ft_putstr("\033[35mAND NOW ? : \033[0m"); jump; init(box, (ft_random((box->size * box->size), 0))); print_tab(box); } return (0); }
void glLightSwitch::create_components( ) { m_plate.set_color( 0xFFBFBF7F); m_plate.height = 3; m_plate.width = 2.5; m_plate.depth = 0.125; m_plate.setup(); m_components.push_back(&m_plate); m_lever.set_color( 0xFFFFFF00); m_lever.height = 0.25; m_lever.width = 0.25; m_lever.depth = 0.75; m_lever.grab_back(); m_lever.setup(); m_lever.grab_back(); m_components.push_back(&m_lever); m_lever.relocate( 0.0, 0.0, 0 ); turn_up(); }
/** * Turn servo towards 'pos' in 1 microsecond steps, waiting delay_ms * milliseconds between steps (speed = 1/delay). If check_weight weight * is true, might abort with WHERE_THE_FUCK_IS_THE_CUP error. If a valid pointer * stable_weight is passed, turns bottle until a stable weight is measured * (returns WEIGHT_NOT_STABLE if pos is reached before weight stable). * * Returns 0 when the position is reached or SERVO_OUT_OF_RANGE on error. * * For details about the built-in Servo class see: * /usr/share/arduino/libraries/Servo/Servo.cpp * */ errv_t Bottle::turn_to(int pos, int delay_ms, bool check_weight, int* stable_weight, bool enable_abortcheck) { int weight_previous1 = -9999; // just any impossible value int weight_previous2 = -9999; // ..before we have real values if (pos < SERVO_MIN || pos > SERVO_MAX) { DEBUG_MSG_LN("Invalid pos"); return SERVO_OUT_OF_RANGE; } int current_pos = servo.readMicroseconds(); if (pos == current_pos) return 0; int step = (current_pos < pos) ? 1 : -1; DEBUG_START(); DEBUG_MSG("turn "); DEBUG_MSG(number); DEBUG_MSG(", params "); DEBUG_VAL(current_pos); DEBUG_VAL(step); DEBUG_VAL(pos); DEBUG_VAL(delay_ms); DEBUG_END(); unsigned long last_called = millis(); for (int i = current_pos + step; i * step <= pos * step; i += step) { // ˆˆˆˆˆˆ ˆˆˆˆˆˆ // this inverts the relation if turning down // Warning: printing to serial delays turning! // Might help to to debug servo movement. Not necessary now, commenting // out to save bytes. //if (print_steps && i % 10 == 0) { // DEBUG_VAL_LN(i); //} // check abort only if not already aborted... if (enable_abortcheck) { // turn up and return if we should abort... errv_t ret = check_aborted(); if (ret) { // turn_up might not be necessary here, called another time // later (does not matter if called twice) turn_up(FAST_TURN_UP_DELAY, false); return ret; } } if (check_weight || stable_weight) { int weight; int ret = ads1231_get_noblock(weight); if (ret == 0) { // we got a valid weight from scale if (check_weight && weight < WEIGHT_EPSILON) { return WHERE_THE_FUCK_IS_THE_CUP; } // get next weight sample and return if weight is stable if (stable_weight) { if (weight_previous2 == weight_previous1 && weight_previous1 == weight) { *stable_weight = weight; return 0; } weight_previous2 = weight_previous1; weight_previous1 = weight; } } else if (ret != ADS1231_WOULD_BLOCK) { // ignoring if it would take too long to get weight, but // return in case of other error != 0 return ret; } } // turn servo one step delay(delay_ms); servo.writeMicroseconds(i); } // pos reached before weight stable if (stable_weight) { return WEIGHT_NOT_STABLE; } return 0; }