element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum HELP PLS
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 4 replies
  • Answers 3 answers
  • Subscribers 393 subscribers
  • Views 536 views
  • Users 0 members are here
  • 1 to 10
  • count
  • arduino
Related

HELP PLS

hadn05
hadn05 over 7 years ago

Well I want a variable to go like 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and then reset to 1 and then goes from 1 to 20. HOW DO I DO IT??

  • Sign in to reply
  • Cancel

Top Replies

  • koudelad
    koudelad over 7 years ago +3 suggested
    https://www.arduino.cc/reference/en/language/structure/control-structure/for/
  • 14rhb
    14rhb over 7 years ago in reply to scmclain +3 suggested
    I'm sure there are many E14 members who could write the exact code you are after, but I suggest a better way to understand it would be to try out the code in your own Arduino IDE - e.g. the code that scmclain…
  • scmclain
    scmclain over 7 years ago in reply to hadn05 +2 suggested
    Let me try to explain the example code from the link above. I am on my phone, so this may not work so well. Example Code // Dim an LED using a PWM pin int PWMpin = 10 ; // LED in series with 470 ohm resistor…
Parents
  • koudelad
    0 koudelad over 7 years ago

    https://www.arduino.cc/reference/en/language/structure/control-structure/for/

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • hadn05
    0 hadn05 over 7 years ago in reply to koudelad

    can you give me the code I don't really understand the for loop thingy @koudelad

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • scmclain
    0 scmclain over 7 years ago in reply to hadn05

    Let me try to explain the example code from the link above. I am on my phone, so this may not work so well.

     

    Example Code

     

    // Dim an LED using a PWM pin 
    int PWMpin = 10; // LED in series with 470 ohm resistor on pin 10 

    void setup()
    { // no setup needed } 
    void loop()
    { for (int i=0; i <= 255; i++)
    { analogWrite(PWMpin, i);
    delay(10); }
    }

     

    The line that has the “for” function declares variable “i” as an integer and sets the value to 0. The “for” loop will run as long as i is less than or equal to 255. It will send the value of i to the PWM pin to vary the brightness of the LED. the i++ means that the variable i gets incremented each loop.

     

    instead of writing the value of i to a pin, you could print it instead.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • 14rhb
    0 14rhb over 7 years ago in reply to scmclain

    I'm sure there are many E14 members who could write the exact code you are after, but I suggest a better way to understand it would be to try out the code in your own Arduino IDE - e.g. the code that scmclain has kindly just explained. Then start to adjust that code and hopefully how it works will become clearer. If you get stuck then post the error messages and your existing code and we'll help you along image.

     

    If you understand what scmclain has explained then you may want to look up 'nested loops' to do your two separate counts (like this link at Tutorialspoint ).

     

    Rod

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • 14rhb
    0 14rhb over 7 years ago in reply to scmclain

    I'm sure there are many E14 members who could write the exact code you are after, but I suggest a better way to understand it would be to try out the code in your own Arduino IDE - e.g. the code that scmclain has kindly just explained. Then start to adjust that code and hopefully how it works will become clearer. If you get stuck then post the error messages and your existing code and we'll help you along image.

     

    If you understand what scmclain has explained then you may want to look up 'nested loops' to do your two separate counts (like this link at Tutorialspoint ).

     

    Rod

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube