robot c for cortex while loops part 2 l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
ROBOT C for CORTEX While Loops Part 2 PowerPoint Presentation
Download Presentation
ROBOT C for CORTEX While Loops Part 2

Loading in 2 Seconds...

play fullscreen
1 / 17

ROBOT C for CORTEX While Loops Part 2 - PowerPoint PPT Presentation


  • 1129 Views
  • Uploaded on

ROBOT C for CORTEX While Loops Part 2. Timers. More loop control please? Question: Where would the wait statement go if we wanted the loop to repeat for a controlled amount of time? Answer: Nowhere! We need something else. Solution: Timers

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'ROBOT C for CORTEX While Loops Part 2' - queenie


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
timers
Timers
  • More loop control please?
    • Question: Where would the wait statement go if we wanted the loop to repeat for a controlled amount of time?
    • Answer: Nowhere! We need something else.
  • Solution: Timers
    • Can be thought of as internal stopwatches (4 available)
    • Like encoders, timers should be “cleared” anytime before they are used
      • Watch where you clear them!
while loop exercise 4
While Loop Exercise 4
  • Example: Program the greenLED to repeatedly turn on for 2 seconds, then off for 2 seconds, while less than 20 seconds have elapsed.
timers6
Timers
  • Follow along with the Remote Control > Timers Videos for Review
variables
Variables
  • A variable is a space in your robot’s memory where you can store data, such as whole numbers, decimal numbers, and words.
  • Variable names follow the same rules as custom motor and sensor names:
    • Capitalization, Spelling, Availability
  • Usefulness
    • Can store data to be manipulated by your robot
    • Can improve the readability and expandability of your programs
creating a variable
Creating a Variable
  • To create a variable, you must “declare” a type, which is the type of data it will hold, as well as a name that it can be referenced by:
  • Variables can be set to different values throughout your program. Giving a variable its initial value is called “initializing” it
variables exercise
Variables Exercise
  • Example: Create a count-based while loop that turns a motor on for 5 seconds, then off for 5 seconds, 3 times.
while loop exercise
While Loop Exercise
  • Example 3: Program the right motor to spin forward until the potentiometer value is greater than 2048. Then program it to spin in reverse until the potentiometer value is less than 2048. Repeat while the limit switch isn’t pressed.
equivalent solution code
Equivalent Solution Code
  • “until” commands are implemented as while loops in the Natural Language
equivalent solution code15
Equivalent Solution Code
  • Program Flow gets stuck in these locations. How do we avoid this?
cmu resources
CMU Resources
  • ROBOTC.net: http://www.robotc.net/
    • The ROBOTC Forum: http://www.robotc.net/forums/
    • Post your homework and questions here!
  • ROBOTC PLTW Page: http:// www.robotc.net/pltw
  • VEX Cortex Video Trainer
    • http://www.education.rec.ri.cmu.edu/products/teaching_robotc_cortex/index.html
  • Robotics Academy
    • http://www.education.rec.ri.cmu.edu/content/vex/index.htm
homework
Homework
  • Program the flashlight or greenLED to repeatedly turn on for 5 seconds, then off for 5 seconds, while less than 1 minute has elapsed.
  • Create a count based while loop that turns on the left motor for 3 seconds, then off for 3 seconds, 5 times.