View unanswered posts | View active topics It is currently Mon Dec 22, 2014 12:29 pm






Reply to topic  [ 6 posts ] 
rising edge 
Author Message
Rookie
User avatar

Joined: Sun Nov 11, 2012 4:26 am
Posts: 8
Location: France
Post 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();
}

_________________
ROBOTC 3.61.1

French guy - I Love ROCK and ROBOTS


Mon Jan 14, 2013 4:18 pm
Profile
Rookie
User avatar

Joined: Sun Nov 11, 2012 4:26 am
Posts: 8
Location: France
Post 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();
}

}

_________________
ROBOTC 3.61.1

French guy - I Love ROCK and ROBOTS


Mon Jan 14, 2013 4:30 pm
Profile
Rookie

Joined: Thu Sep 13, 2012 9:43 am
Posts: 47
Post 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!


Tue Jan 15, 2013 3:13 am
Profile
Rookie
User avatar

Joined: Sun Nov 11, 2012 4:26 am
Posts: 8
Location: France
Post 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.

_________________
ROBOTC 3.61.1

French guy - I Love ROCK and ROBOTS


Tue Jan 15, 2013 5:01 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1372
Post 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();
}


Tue Jan 15, 2013 2:35 pm
Profile
Rookie
User avatar

Joined: Sun Nov 11, 2012 4:26 am
Posts: 8
Location: France
Post 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:

_________________
ROBOTC 3.61.1

French guy - I Love ROCK and ROBOTS


Tue Jan 15, 2013 6:12 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.