I have provided code below and the serial output of the array. Each value would correspond with a function that I have written. Experiment a little, and add another case statement for a different maneuver, such as pivot-backward-left, then add some characters for the new maneuver to your array string.I am trying to move a stepper motor with an array.Keep in mind that they have to be added to the left of the s character for the sketch to get to them. Add ten or so h characters to your maneuvers character array.ServoLeft.writeMicroseconds(1550) // Half speed forward Use the character 'h', and remember that the linear speed range for the servos is from 1400 to 1600 microsecond pulses. Try adding a case for half-speed forward.Without that break at the end of each case, the sketch would continue through to the code for the next case, resulting in un-requested maneuvers. So, each call to go results in a 200 ms maneuver. The break in each case exits the switch block and the sketch moves on to the next command, which is delay(200). If it passes b, the full-speed backward code gets executed. If the go function call passes the f character to the c parameter, the code in case f is executed-the familiar full-speed-forward. For each of the five letters in the maneuvers character array, there is a corresponding case statement in the switch(c) block that will be executed if that character is received by go. ![]() ![]() It receives each character passed to its c parameter, and evaluates it on a case-by-case basis using a switch/case statement. This continues while(maneuvers != 's') which means “while the value fetched from the maneuvers array is not equal to 's'. The ++ in index++ adds one to the index variable for the next time through the loop-recall that this is the post increment operator. Each time through the loop, go(maneuvers) passes the character at maneuvers to the go function. Similar to a regular while loop, do-while repeatedly executes commands inside its code block while a condition is true, but the while part comes after its block so the block always executes at least once. int index = 0 įirst, index is declared and initialized to zero, to be used in a do-while loop.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |