Is there a problem with my While loop of SensorValue[bump]==0












0















I’m trying to make a loop where a motor will run and lights will cycle indefinitely as long as the button is not pressed yet when the while(SensorValue[bump]==0) will only run once even if the button isn’t pressed.



#pragma config(Sensor, dgtl2,  bump, sensorNone)
#pragma config(Sensor, dgtl10, green, sensorLEDtoVCC)
#pragma config(Sensor, dgtl11, red, sensorLEDtoVCC)
#pragma config(Sensor, dgtl12, amber, sensorLEDtoVCC)
#pragma config(Motor, port2, fan,tmotorVex393_MC29, openLoop)


task main()
{
while(true){
untilBump(bump); //waits until button is pressed
while(SensorValue(bump)==0){

startMotor(fan,127); //startmotor

turnLEDOn(green); //turn green on
delay(2000);
turnLEDOff(green); //turn green off

turnLEDOn(amber); //turn amber on
delay(2000);
turnLEDOff(amber); //turn amber off

turnLEDOn(red); //turn red on
delay(2000);
turnLEDOff(red); //turn red off

}

stopMotor(fan);
}

}









share|improve this question







New contributor




Collin Smallegan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Another thing to note is that you are never going to escape the first while loop without a break or return.

    – busybear
    Jan 18 at 16:19











  • I don't know anything about robotc, but it looks to me like you have a few issues with these loops. Your motor will likely be told to start multiple times without stopping (the stop is outside the while(true) loop, even). Your trigger condition causes a process that takes at least 6 seconds to complete in a (presumably) single-threaded system. I think you've assigned bump to sensorNone which seems logically incorrect and you should always expect the same value out of it (probably 0).

    – Ian MacDonald
    Jan 18 at 16:19











  • Robotc is just a really strange language, bump is mapped to port dgtl2 and will out put a 1 or a 0 depending on if it’s pressed, robot c also doesn’t use breaks. This is a example of the languages while loops staffordhs.ss8.sharpschool.com/common/pages/…

    – Collin Smallegan
    Jan 18 at 16:23













  • My stop motor is also inside the while(true), basically after the button is pressed it will break the loop then the motor will stop, the code will then start at the top right at untilBump(bump)

    – Collin Smallegan
    Jan 18 at 16:25
















0















I’m trying to make a loop where a motor will run and lights will cycle indefinitely as long as the button is not pressed yet when the while(SensorValue[bump]==0) will only run once even if the button isn’t pressed.



#pragma config(Sensor, dgtl2,  bump, sensorNone)
#pragma config(Sensor, dgtl10, green, sensorLEDtoVCC)
#pragma config(Sensor, dgtl11, red, sensorLEDtoVCC)
#pragma config(Sensor, dgtl12, amber, sensorLEDtoVCC)
#pragma config(Motor, port2, fan,tmotorVex393_MC29, openLoop)


task main()
{
while(true){
untilBump(bump); //waits until button is pressed
while(SensorValue(bump)==0){

startMotor(fan,127); //startmotor

turnLEDOn(green); //turn green on
delay(2000);
turnLEDOff(green); //turn green off

turnLEDOn(amber); //turn amber on
delay(2000);
turnLEDOff(amber); //turn amber off

turnLEDOn(red); //turn red on
delay(2000);
turnLEDOff(red); //turn red off

}

stopMotor(fan);
}

}









share|improve this question







New contributor




Collin Smallegan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Another thing to note is that you are never going to escape the first while loop without a break or return.

    – busybear
    Jan 18 at 16:19











  • I don't know anything about robotc, but it looks to me like you have a few issues with these loops. Your motor will likely be told to start multiple times without stopping (the stop is outside the while(true) loop, even). Your trigger condition causes a process that takes at least 6 seconds to complete in a (presumably) single-threaded system. I think you've assigned bump to sensorNone which seems logically incorrect and you should always expect the same value out of it (probably 0).

    – Ian MacDonald
    Jan 18 at 16:19











  • Robotc is just a really strange language, bump is mapped to port dgtl2 and will out put a 1 or a 0 depending on if it’s pressed, robot c also doesn’t use breaks. This is a example of the languages while loops staffordhs.ss8.sharpschool.com/common/pages/…

    – Collin Smallegan
    Jan 18 at 16:23













  • My stop motor is also inside the while(true), basically after the button is pressed it will break the loop then the motor will stop, the code will then start at the top right at untilBump(bump)

    – Collin Smallegan
    Jan 18 at 16:25














0












0








0








I’m trying to make a loop where a motor will run and lights will cycle indefinitely as long as the button is not pressed yet when the while(SensorValue[bump]==0) will only run once even if the button isn’t pressed.



#pragma config(Sensor, dgtl2,  bump, sensorNone)
#pragma config(Sensor, dgtl10, green, sensorLEDtoVCC)
#pragma config(Sensor, dgtl11, red, sensorLEDtoVCC)
#pragma config(Sensor, dgtl12, amber, sensorLEDtoVCC)
#pragma config(Motor, port2, fan,tmotorVex393_MC29, openLoop)


task main()
{
while(true){
untilBump(bump); //waits until button is pressed
while(SensorValue(bump)==0){

startMotor(fan,127); //startmotor

turnLEDOn(green); //turn green on
delay(2000);
turnLEDOff(green); //turn green off

turnLEDOn(amber); //turn amber on
delay(2000);
turnLEDOff(amber); //turn amber off

turnLEDOn(red); //turn red on
delay(2000);
turnLEDOff(red); //turn red off

}

stopMotor(fan);
}

}









share|improve this question







New contributor




Collin Smallegan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I’m trying to make a loop where a motor will run and lights will cycle indefinitely as long as the button is not pressed yet when the while(SensorValue[bump]==0) will only run once even if the button isn’t pressed.



#pragma config(Sensor, dgtl2,  bump, sensorNone)
#pragma config(Sensor, dgtl10, green, sensorLEDtoVCC)
#pragma config(Sensor, dgtl11, red, sensorLEDtoVCC)
#pragma config(Sensor, dgtl12, amber, sensorLEDtoVCC)
#pragma config(Motor, port2, fan,tmotorVex393_MC29, openLoop)


task main()
{
while(true){
untilBump(bump); //waits until button is pressed
while(SensorValue(bump)==0){

startMotor(fan,127); //startmotor

turnLEDOn(green); //turn green on
delay(2000);
turnLEDOff(green); //turn green off

turnLEDOn(amber); //turn amber on
delay(2000);
turnLEDOff(amber); //turn amber off

turnLEDOn(red); //turn red on
delay(2000);
turnLEDOff(red); //turn red off

}

stopMotor(fan);
}

}






robotc






share|improve this question







New contributor




Collin Smallegan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Collin Smallegan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Collin Smallegan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Jan 18 at 16:08









Collin SmalleganCollin Smallegan

1




1




New contributor




Collin Smallegan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Collin Smallegan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Collin Smallegan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Another thing to note is that you are never going to escape the first while loop without a break or return.

    – busybear
    Jan 18 at 16:19











  • I don't know anything about robotc, but it looks to me like you have a few issues with these loops. Your motor will likely be told to start multiple times without stopping (the stop is outside the while(true) loop, even). Your trigger condition causes a process that takes at least 6 seconds to complete in a (presumably) single-threaded system. I think you've assigned bump to sensorNone which seems logically incorrect and you should always expect the same value out of it (probably 0).

    – Ian MacDonald
    Jan 18 at 16:19











  • Robotc is just a really strange language, bump is mapped to port dgtl2 and will out put a 1 or a 0 depending on if it’s pressed, robot c also doesn’t use breaks. This is a example of the languages while loops staffordhs.ss8.sharpschool.com/common/pages/…

    – Collin Smallegan
    Jan 18 at 16:23













  • My stop motor is also inside the while(true), basically after the button is pressed it will break the loop then the motor will stop, the code will then start at the top right at untilBump(bump)

    – Collin Smallegan
    Jan 18 at 16:25



















  • Another thing to note is that you are never going to escape the first while loop without a break or return.

    – busybear
    Jan 18 at 16:19











  • I don't know anything about robotc, but it looks to me like you have a few issues with these loops. Your motor will likely be told to start multiple times without stopping (the stop is outside the while(true) loop, even). Your trigger condition causes a process that takes at least 6 seconds to complete in a (presumably) single-threaded system. I think you've assigned bump to sensorNone which seems logically incorrect and you should always expect the same value out of it (probably 0).

    – Ian MacDonald
    Jan 18 at 16:19











  • Robotc is just a really strange language, bump is mapped to port dgtl2 and will out put a 1 or a 0 depending on if it’s pressed, robot c also doesn’t use breaks. This is a example of the languages while loops staffordhs.ss8.sharpschool.com/common/pages/…

    – Collin Smallegan
    Jan 18 at 16:23













  • My stop motor is also inside the while(true), basically after the button is pressed it will break the loop then the motor will stop, the code will then start at the top right at untilBump(bump)

    – Collin Smallegan
    Jan 18 at 16:25

















Another thing to note is that you are never going to escape the first while loop without a break or return.

– busybear
Jan 18 at 16:19





Another thing to note is that you are never going to escape the first while loop without a break or return.

– busybear
Jan 18 at 16:19













I don't know anything about robotc, but it looks to me like you have a few issues with these loops. Your motor will likely be told to start multiple times without stopping (the stop is outside the while(true) loop, even). Your trigger condition causes a process that takes at least 6 seconds to complete in a (presumably) single-threaded system. I think you've assigned bump to sensorNone which seems logically incorrect and you should always expect the same value out of it (probably 0).

– Ian MacDonald
Jan 18 at 16:19





I don't know anything about robotc, but it looks to me like you have a few issues with these loops. Your motor will likely be told to start multiple times without stopping (the stop is outside the while(true) loop, even). Your trigger condition causes a process that takes at least 6 seconds to complete in a (presumably) single-threaded system. I think you've assigned bump to sensorNone which seems logically incorrect and you should always expect the same value out of it (probably 0).

– Ian MacDonald
Jan 18 at 16:19













Robotc is just a really strange language, bump is mapped to port dgtl2 and will out put a 1 or a 0 depending on if it’s pressed, robot c also doesn’t use breaks. This is a example of the languages while loops staffordhs.ss8.sharpschool.com/common/pages/…

– Collin Smallegan
Jan 18 at 16:23







Robotc is just a really strange language, bump is mapped to port dgtl2 and will out put a 1 or a 0 depending on if it’s pressed, robot c also doesn’t use breaks. This is a example of the languages while loops staffordhs.ss8.sharpschool.com/common/pages/…

– Collin Smallegan
Jan 18 at 16:23















My stop motor is also inside the while(true), basically after the button is pressed it will break the loop then the motor will stop, the code will then start at the top right at untilBump(bump)

– Collin Smallegan
Jan 18 at 16:25





My stop motor is also inside the while(true), basically after the button is pressed it will break the loop then the motor will stop, the code will then start at the top right at untilBump(bump)

– Collin Smallegan
Jan 18 at 16:25












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Collin Smallegan is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257605%2fis-there-a-problem-with-my-while-loop-of-sensorvaluebump-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








Collin Smallegan is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Collin Smallegan is a new contributor. Be nice, and check out our Code of Conduct.













Collin Smallegan is a new contributor. Be nice, and check out our Code of Conduct.












Collin Smallegan is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257605%2fis-there-a-problem-with-my-while-loop-of-sensorvaluebump-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage