Plz Help; SWITCH PROBLEM (in NXC program idea) ??
Posted: 08 Dec 2011, 12:23
This program takes input from 2 touch sensors; where you have to Click the First touch sensor (1 or 2 times) then the Second touch sensor (1 or 2 times)
But it seems like It doesn't work
Plz help ..
- If the first touch sensor pressed 1 time -->it will move 1 meter
If the first touch sensor pressed 2 times --> it will move 2 meters
If the Second touch sensor pressed 1 time --> it will move 5 meters
If the Second touch sensor pressed 2 times --> it will move 10 meters
Code: Select all
#include "NXCDefs.h"
bool button_bumped(const byte btn)
{ bool result = false;
if (ButtonPressed(btn, false))
{ while (ButtonPressed(btn, true));
PlayFile("! Click.rso");
result = true;
}
return result;
}
//========================================================
task main() {
int touchCounter1, touchCounter2; // count how many times touch sensor pressed
SetSensor(IN_1, SENSOR_TOUCH);
SetSensor(IN_2, SENSOR_TOUCH);
TextOut (10, LCD_LINE1, "THE FIRST DISTANCE " );
touchCounter1 = 0;
while(!(button_bumped(BTNCENTER)) & touchCounter1<6 )
{
if(SENSOR_1 == 1) {
//TextOut (10, LCD_LINE4, " Pressed");
NumOut(10,LCD_LINE2,touchCounter1);
touchCounter1 = touchCounter1 + 1;
Wait(1000);
}
else {
TextOut (10, LCD_LINE2, " " );
//Wait(1000);
}
} // end while
NumOut(10,LCD_LINE2,touchCounter1);
TextOut (10, LCD_LINE3, "THE SCOND DISTANCE " );
touchCounter2 = 0;
while(!(button_bumped(BTNCENTER)))
{
if(SENSOR_2 == 1) {
//TextOut (10, LCD_LINE4, " Pressed");
NumOut(10,LCD_LINE4,touchCounter2);
touchCounter2 = touchCounter2 + 1;
Wait(1000);
}
else {
TextOut (10, LCD_LINE4, " " );
//Wait(1000);
}
} // end while
NumOut(10,LCD_LINE4,touchCounter2);
switch(touchCounter1) {
case 1:
{
switch(touchCounter2){
case 1:
{
do{
OnFwd(OUT_BC, 75);
while (MotorRotationCount(OUT_BC)<XX ); //I didn't calculate it yet X)
Off(OUT_BC);
}
Case 2:
{
do{
OnFwd(OUT_BC, 75);
while (MotorRotationCount(OUT_BC)<XX ); //I didn't calculate it yet X)
Off(OUT_BC);
}
}
Case 2:
//same before
}
}
} // end main
Plz help ..