ROBOTC.net forums
http://www.robotc.net/forums/

rising edge
http://www.robotc.net/forums/viewtopic.php?f=1&t=5364
Page 1 of 1

Author:  robotcexperiences [ Mon Jan 14, 2013 4:18 pm ]
Post subject:  rising edge

Hye,

I need to program a task using rising edge. I do it with this few lines, but i' think it's possible to do it


Code:
task _sendData(){
bool _done;
bool _sensorTouchHightLevel;
   while(!_done){
      if(SensorValue[TOR]){
                 if(!_sensorTouchHightLevel){
           _sensorTouchHightLevel= !_sensorTouchHightLevel;
           //
           // process hère
           //
      }
    }
    else _sensorTouchHightLevel = false;
   EndTimeSlice();
}

Author:  robotcexperiences [ Mon Jan 14, 2013 4:30 pm ]
Post subject:  Re: rising edge

Sorry,

I click on the bad button (Submit instead Preview)


Hye,

I need to program a task using rising edge. I do it with this few lines, but i' think it's possible to do it much easier.

Have you got an idea ?

Code:
task _sendData(){
bool _done;
bool _sensorTouchHightLevel;
   while(!_done){
      if(SensorValue[TOR]){
      if(!_sensorTouchHightLevel){
           _sensorTouchHightLevel= !_sensorTouchHightLevel;
           //
           PlayTone(200, 200);
           
           //
      }
    }
    else _sensorTouchHightLevel = false;
   EndTimeSlice();
}

}

Author:  MikeJMcFarlane [ Tue Jan 15, 2013 3:13 am ]
Post subject:  Re: rising edge

robotcexperiences wrote:
Sorry,

I click on the bad button (Submit instead Preview)


Hye,

I need to program a task using rising edge. I do it with this few lines, but i' think it's possible to do it much easier.

Have you got an idea ?

Code:
task _sendData(){
bool _done;
bool _sensorTouchHightLevel;
   while(!_done){
      if(SensorValue[TOR]){
      if(!_sensorTouchHightLevel){
           _sensorTouchHightLevel= !_sensorTouchHightLevel;
           //
           PlayTone(200, 200);
           
           //
      }
    }
    else _sensorTouchHightLevel = false;
   EndTimeSlice();
}

}


A while statement to wait while the touch sensor is low/untouched might be slightly more compact?
e.g.
Code:
while(!_done){
           while (touch sensor low){
                      // wait
           }
           // do your thing
           // you might want to debounce or wait for the sensor to go low again at some point?
}

But if what you have works, it looks ok!

Author:  robotcexperiences [ Tue Jan 15, 2013 5:01 am ]
Post subject:  Re: rising edge

Hye MikeJMcFarlane,

Thanks for your reply.

In my program, when you push the sensor touch, the sound is playing only one time.
To play it again, you still release the touch sensor and press it , it's just like a pulse .


I don't understand "touch sensor low" it's not a RobotC command ? :?:

I can't try your program, I'm not at home today.

Author:  MHTS [ Tue Jan 15, 2013 2:35 pm ]
Post subject:  Re: rising edge

This is not necessarily "easier", but it is another way to do it. IMHO, it may be easier to understand and more flexible because it allows you to detect both the rising edge and the falling edge.
Code:
int prevTouchState = SensorValue[TOR];
while (true)
{
    int touchState = SensorValue[TOR];
    if (touchState != prevTouchState)
    {
        //
        // Detecting an edge event, pressed or released.
        //
        if (touchState != 0)
        {
            // Touch sensor is pressed.
            PlayTone(880, 200);
        }
        else
        {
            // Touch sensor is released.
            PlayTone(440, 200);
        }
        prevTouchState = touchState;
    }
    EndTimeSlice();
}

Author:  robotcexperiences [ Tue Jan 15, 2013 6:12 pm ]
Post subject:  Re: rising edge

Hye MHTS,

You're right, it's not "easier" but now we've got a complete rising edge/falling edge.

In fact, i use the rising edge to send datas with bluetooth to another NXT.
A robot resolves a random maze and sends data to a second NXT.

The second one, draws on his display the robot course and the maze.

When the maze is completly resolve, the second NXT is like a remote control to deplace robot on the maze.

What a funny project ! :lol:

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/