当前位置: 首页>>代码示例>>C++>>正文


C++ Timeout::attach方法代码示例

本文整理汇总了C++中Timeout::attach方法的典型用法代码示例。如果您正苦于以下问题:C++ Timeout::attach方法的具体用法?C++ Timeout::attach怎么用?C++ Timeout::attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Timeout的用法示例。


在下文中一共展示了Timeout::attach方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: updateMotors

void updateMotors() {
    
    if(motor1) to1.attach(&shot1,0.2);
    if(motor2) to2.attach(&shot2,.2);
    if(motor3) to3.attach(&shot3,.2);
    if(motor4) to4.attach(&shot4,.2);
    //if(motor5) to5.attach(&shot5,.2);
    if(motor6) to6.attach(&shot6,.2);
}
开发者ID:ESE519,项目名称:i-Tv,代码行数:9,代码来源:vest-osc-mrf.cpp

示例2: beep

void beep(float freq, float time)
{
  buzzer.period(1.0 / freq);
  buzzer.write(0.5);
  toff.attach(nobeep, time);
  led = 0;
}
开发者ID:CMUBOOST,项目名称:BOOST_Stalker,代码行数:7,代码来源:GroveBuzzer.cpp

示例3:

//Creates the gyro using given input and calibrates asynchronously it over 2 seconds.
Gyro::Gyro(PinName input): _input(input){
    _isOn = false;
    degrees = 0;
    nullVoltage = 0.7576;
    
    gyroTimeOut.attach(this, &Gyro::calibrate, 1.0); //Delays 1 second before actually calibrating
}
开发者ID:austinxiao-ucsd,项目名称:falcon,代码行数:8,代码来源:gyro.cpp

示例4: main

int main() {
    printf("Hello world!\n");
    printf("LED1 will blink every second, LED3 will toggle after 2.5 seconds, LED2 can be toggled through BUTTON1.\n");
    printf("-----------------------------------\n\n");

    t1.attach(callback(&blink_led1), 1.0f);
    t2.attach(callback(&turn_led3_on), 2.5f);
    btn.fall(callback(&toggle_led2));

    wait_ms(osWaitForever);
}
开发者ID:janjongboom,项目名称:mbed-simulator,代码行数:11,代码来源:main.cpp

示例5: main

int main() 
{

    pc.baud(115200);
    NUCLEO.baud(921600);
    printf("HEXACOPTER MBED SOFTWARE\n");
    init();
    wait(1);
    NUCLEO.putc('S');
    wait(0.01);
    while(1) 
    {
        safeGuard.attach(&safeGuardOff, 0.2);
        if (counter == 100)
        {
            counter = 0;
            led1 = !led1;
            if (Msg.err_state != 5 && !rec_msg)
            {
                led2 = !led1;
            }
            else if (Msg.err_state != 5)
            {
                led2 = 0;
            }
            rec_msg = false;
            switch (Msg.err_state)
            {
                case 2:
                    led3 = !led1;
                    if (led3 == 1) buzz.beep_once();
                    led2 = 0;
                    led4 = 0;
                    break;
                case 3:
                    led2 = !led1;
                    led3 = !led1;
                    if (led3 == 1) buzz.beep_twice();
                    led4 = 0;
                    break;
                case 4:
                    led4 = !led1;
                    if (led4 == 1) buzz.beep_thrice();
                    led2 = 0;
                    led3 = 0;
                    break;
                case 5:
                    led4 = !led1;   
                    led3 = !led1;
                    led2 = !led1;
                    if (led4 == 1) buzz.long_beep();
                    if (res_err_cnt >= MAX_WAIT)
                    {
                        res_err_cnt = 0;
                        mbed_reset();
                    }
                    res_err_cnt++;
                    break;
                default:
                    led2 = 0;
                    led3 = 0;
                    led4 = 0;
                    break;
            }
        }
        Msg.batt = bl.GetLevel();
        char * msg_array = (char *)&Msg;
        for (int i = 0; i < msg_size; i++)
        {
            NUCLEO.getc();
            NUCLEO.putc(msg_array[i]);
        }
        buffer = (char *) &Rec;
        while (!NUCLEO.readable());
        for (int i = 0; i < rec_size; i++)
        {
            buffer[i] = NUCLEO.getc();
        }
		for (int i = 0; i < 6; i++)
		{
			motors.pulsewidth(i,Rec.motor_speeds[i]);
		}
		switch (Rec.buzz_val)
		{
			case 0:
				//do nothing.
				break;
			case 1:
				buzz.beep_once();
				break;
			case 2:
				buzz.beep_twice();
				break;
			case 3:
				buzz.beep_thrice();
				break;
			case 4:
				buzz.long_beep();
				break;
			default:
//.........这里部分代码省略.........
开发者ID:scottyjoe9,项目名称:SJDrone,代码行数:101,代码来源:main.cpp

示例6: blip4

void blip4(void) { led4 = 1; t4.attach(&t4out, 0.05); }
开发者ID:fmonpelat,项目名称:Mbed-Jeep,代码行数:1,代码来源:example3.cpp

示例7: blip3

void blip3(void) { led3 = 1; t3.attach(&t3out, 0.05); }
开发者ID:fmonpelat,项目名称:Mbed-Jeep,代码行数:1,代码来源:example3.cpp

示例8: blip2

void blip2(void) { led2 = 1; t2.attach(&t2out, 0.05); }
开发者ID:fmonpelat,项目名称:Mbed-Jeep,代码行数:1,代码来源:example3.cpp

示例9: line_following

void line_following(void)
{
    // local variables
    const float     speed = 0.2;
    const float     correction = 0.1;
    const float     threshold = 0.5;

    m3pi.locate(0,1);
    m3pi.printf("Line Flw");        // print on LCD display

    wait(2.0);

    m3pi.sensor_auto_calibrate();
    t.attach(&isr_timeout, 5.0);        // attach isr for timeout

    while (1) {

        // check for obstacles along the path
        if (object_presence() > 0) {

            //an obstacle has been detected
            m3pi.right_motor(0.2);      // turn right
            m3pi.left_motor(0.1);
            wait(1);
            m3pi.left_motor(0.2);       // then turn left
            m3pi.right_motor(0.1);
            wait(1);
            m3pi.forward(0.1);          // forward
            wait(1);
        }
        else {
            /* Line following algorithm */

            // -1.0 is far left, 1.0 is far right, 0.0 in the middle
            float position_of_line = m3pi.line_position();

            // Line is more than the threshold to the right, slow the left motor
            if (position_of_line > threshold) {
                m3pi.right_motor(speed);
                m3pi.left_motor(speed-correction);
            }

            // Line is more than 50% to the left, slow the right motor
            else if (position_of_line < -threshold) {
                m3pi.left_motor(speed);
                m3pi.right_motor(speed-correction);
            }

            // Line is in the middle
            else {
                m3pi.forward(speed);
            }
        }

        // check if timeout has expired
        if(flags.flag_timeout_measurement) {

            if(flags.flag_timeout_expired) {
                t.detach();
                m3pi.stop();
                goto end_routine;               //jump out of the loop
            }
            else {
                //obtain measurement
                flags.flag_timeout_expired = 0b1;           //set the flag
                flags.flag_timeout_measurement = 0b0;       //reset flag
                m3pi.stop();                                //stop the 3pi
                obtain_measurement();                       // perform measurement
                t.detach();                                 // reset the timer, must be reloaded
                t.attach(&isr_timeout, 5.0);
            }
        }
    }

    end_routine:
        flags.flag_timeout_expired = 0b0;
        flags.flag_timeout_measurement = 0b0;
}
开发者ID:florix,项目名称:dissertation,代码行数:78,代码来源:main.cpp


注:本文中的Timeout::attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。