So I am having an issue with my switch case programming…My goal is to tap a button on my screen to select different frequencies for a flashing LED. I am not getting any errors at all in my code, but the LED is staying at the frequency that I initially defined it at. Below is what I have so far:
if ((p.x > 110) && (p.x < 235)) {
if ((p.y > 5) && (p.y < 95)) {
count = count++;
if (count = 4) {
count = 0;
switch (count) {
case 0:
frq = 1000;
break;
case 1:
frq = 750;
break;
case 2:
frq = 500;
break;
case 3:
frq = 250;
break;
}
}
}
}
My guess is that my code may not be structured right with where parts are located inside the if statements, but I would totally appreciate some help on the matter!
I tried changing the = to == and still nothing :~ I did get something to work by using:
int frq = 1000;
...
if ((p.x > 110) && (p.x < 235)) {
if ((p.y > 5) && (p.y < 95)) {
frq = frq - 250; // Decreases the frequency by 250ms every push
if (frq = 0) {
frq = 1000; // Once the button is pushed 4 times to reach a value of 0, reset back to 1000
}
}
}
However the problem with this one is that it wouldn’t increment down evenly each time…ie it had to be held down. When this was done, you could see the light changing pulse rates, however when just simply pushed, not held, the flash rate would alternate between 2 speeds. Thanks again for the help fellas!
GSTEC:
So I am having an issue with my switch case programming…My goal is to tap a button on my screen to select different frequencies for a flashing LED. I am not getting any errors at all in my code, but the LED is staying at the frequency that I initially defined it at. Below is what I have so far:
I get the feeling the issue isn't going to be resolved until we see the whole code. How often is that block of code run? In other words, will the top conditions be true only once between frequency changes?
• point_t class to handle point (yes something different than that of the touches lib)
• rect_t class specifying a rect with perhaps a 'point_in_rect' method.
• a button class that makes use of 'point_t' and 'rect_t' for hit testing implementing the touch point down was within the buttons 'rect' and the touch point up was also within the button rect to determine a successful button press.
These don't have to be complicated but will make for more modular, readable, maintainable and debuggable code.