|
151
|
Using Arduino / Programming Questions / Re: Save state of Touch Screen
|
on: April 28, 2013, 11:32:10 am
|
Paul, I see the problem with my idea but will your suggestion work either ? Since either value may be dropping from a good reading back to 0, after a finger is lifted. then all bets are off as to where the finger was when it was touching the screen as no value of Y may be safely regarded as within the "save the X coordinate" range unless I have misunderstood what you meant. I cannot see a way of leaving the LED at its RGB values returned when the finger last touched the screen without the use of another button which is pressed to record X and Y, and released to hold the last recorded values.
|
|
|
|
|
152
|
Using Arduino / Programming Questions / Re: Save state of Touch Screen
|
on: April 28, 2013, 08:35:06 am
|
start of loop read finger position x y if y > 0 if finger in red area save y coordinate to red variable end of if else if finger in green area save y coordinate to green variable end of else else if finger in blue area save y coordinate to blue variable end of else end of if set LED PWM values based on the 3 colour variables end of loop The RGB variables could be a single array with 3 elements if you want.
|
|
|
|
|
153
|
Using Arduino / Programming Questions / Re: Isolate delay for certain pin over the normal sequence of code time.
|
on: April 28, 2013, 08:17:02 am
|
|
As suggested, look at the principle used in the BlinkWithoutDelay example.
Instead of the 'start something, wait until it is finished, now do something else' principle, which blocks execution of other code whilst the 'wait until it is finished' step is executed it works like this. 'start something, has enough time passed for it to finish ?, if so then react, else do something else'. The 'do something else' step can execute each time through the loop() function and can, itself, be another non blocking 'has enough time passed' step.
In this forum you will find many questions about this method of timing and analogies to it taken from real life such as 'put meal in oven, stand by oven until cooked, eat meal, now watch TV' (the blocking approach) and 'put meal in oven, watch TV, check every so often whether enough time has elapsed for the meal to cook, if so eat the meal, else carry on watching TV'
Which would you rather do ?
|
|
|
|
|
155
|
Using Arduino / Programming Questions / Re: Help robot sketch filippo
|
on: April 27, 2013, 04:29:22 pm
|
|
One or more of the following is wrong :
You did not include the IRremote library in your program. The IRremote library is installed in the wrong place on your computer. You did not stop and start the IDE after installing the IRremote library.
|
|
|
|
|
156
|
Using Arduino / Programming Questions / Re: Trying to understand Functions
|
on: April 27, 2013, 12:40:58 pm
|
is both telling the function what variable is to be the result and also what variable is to be read. Is that correct? And it is called because that is where it is in the code. If there where an if statement before that line of code, the if would need to be true before the function is called, correct? Correct. Try changing the value sent to the function from 250 to 1000 to see the effect of passing a different value to the function. Your other observation ie that the program does not do what they say it will, is also correct ! Confusing, or what ?
|
|
|
|
|
157
|
Using Arduino / Programming Questions / Re: Trying to understand Functions
|
on: April 27, 2013, 12:04:15 pm
|
As to the first question, how is your circuit wired ? Is it exactly as in the book ? Your second question, When the blink3() function is called like this int count = blink3(250); the value in the brackets is sent to the function. The function definition int blink3(int period) indicates that it expects to receive an integer and that in the function the name of the variable holding the int will be period. The int preceding the function definition indicates that it will return an integer value, in this case the number of times that the LED blinked (held in the function in the result variable, hence return result). On return from the function this value is assigned to the count variable ready to be printed.
|
|
|
|
|
158
|
Using Arduino / Programming Questions / Re: Case menu structure assistance needed
|
on: April 27, 2013, 11:23:31 am
|
Can I suggest that you make these functions (which you have not included in the code posted), into one function with a parameter for the line to be highlighted. Menu_Line1_Highlighted(); Menu_Line2_Not_Highlighted(); Menu_Line3_Not_Highlighted(); Menu_Line4_Not_Highlighted(); perhaps Menu_Line_Highlighted(1);
There is no need to indicate those that should not be highlighted as, by definition, there will only be one line highlighted at any one time. I am not sure what else you intend to do in the Main_Menu_Case_Switch() function but as you will see, the case number equates to the menu line to be highlighted, so you could eliminate the switch/case structure as it currently stands and substitute a single call to Menu_Line_Highlighted(UP_DOWN_Selector).
|
|
|
|
|
160
|
Using Arduino / Programming Questions / Re: RISING and FALLING ISR on same pin?
|
on: April 27, 2013, 07:07:42 am
|
The ISR digitalRead should be zero when the pin is FALLING If the Arduino reference page is to be believed (not always the case) I agree with you. To quote from the reference page for attachInterrupt() in the section describing interrupt modes. FALLING for when the pin goes from high to low.
|
|
|
|
|
161
|
Using Arduino / Programming Questions / Re: Newbie loop question
|
on: April 27, 2013, 01:14:08 am
|
I am glad it worked. Personally I found it much easier to see what was going on in your latest code when I reformatted if (CurrButtonState == HIGH) //Has the button been pushed ? {digitalWrite(RelayPin1, HIGH); //Fire the solenoid valve and reset the pin Serial.println("Relay 1 fired"); delay(500); etc to if (CurrButtonState == HIGH) //Has the button been pushed ? { digitalWrite(RelayPin1, HIGH); //Fire the solenoid valve and reset the pin Serial.println("Relay 1 fired"); delay(500); etc and used Auto Format on the code to tidy up the indentation
|
|
|
|
|
162
|
Using Arduino / Programming Questions / Re: Restarting loop() ??? M1 Abrams Tank Simulator
|
on: April 27, 2013, 01:03:57 am
|
The code needs to be fast Have you any concept of how fast the Arduino runs ? True, it is not the fastest thing on Earth but it is pretty darned quick compared with anything that your tank will be doing I suspect. Let's look at your requirements from the other way. How fast does does the code need to be ? Your suggested solution of returning to the start of loop() after processing a function is full of holes, not least that it may mean that some functions are never executed. Once a condition in loop() is satisfied and you return to the start, then conditions after the one satisfied will not be tested and this could continue forever. Surely the way to do what you want is to take advantage of the fact that the loop() function does what it says and not to subvert its very purpose. Do not use delay() within functions as that blocks execution of other code, use millis() as a timer instead. I have a simple 2 wheeled vehicle that accelerates up to a fixed speed, maintains straight running by monitoring wheel rotation and monitors the space ahead for obstructions, all done sequentially in loop() with no delays. This uses millis() to determine when each function should be executed. What is it about your tank that needs to be so fast ?
|
|
|
|
|
165
|
Using Arduino / Programming Questions / Re: Newbie loop question
|
on: April 26, 2013, 02:45:40 am
|
OK, but I have spotted a problem. You do not reset StepCount to zero. As to the if tests, please humour me and try the loop() function with curly brackets like this. NOTE the reset of StepCount void loop() { // read the state of the pushbutton value: CurrButtonState = digitalRead(ButtonPin);
if (CurrButtonState != PrevButtonState) { // turn Stepper Pin on: if (CurrButtonState == HIGH) { if (StepCount <=25) { // Loop the number of steps above, check how many needed to rotate drum StepCount++; digitalWrite(StepPin, HIGH); delay(50); digitalWrite(StepPin, LOW); delay(50); } else { // turn LED off: digitalWrite(StepPin, LOW); StepCount = 0; PrevButtonState = CurrButtonState; } } } }
|
|
|
|
|