element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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
Blog Please Help with Program
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Former Member
  • Date Created: 13 Feb 2014 9:18 PM Date Created
  • Views 707 views
  • Likes 0 likes
  • Comments 5 comments
Related
Recommended

Please Help with Program

Former Member
Former Member
13 Feb 2014

Attached is my first attempt at C language programming for my new Arduino UNO R3.

I am unable to understand the VERIFIER's  error messages. Any help would be really appreciated

Beau

New Member

 

Robot ver. 1.0

int Duration=0; // Define a timed variable called Duration and initialize to 0.0 us:
void Setup() {
  pinMode(0,INPUT); // Set Pin D0 as an Input:
  pinMode(1,OUTPUT); // Set Pin D1 as an Output:
  pinMode(2,OUTPUT); // Set Pin D2 as an Output:
}
void loop()  {

  Pulsein(0,HIGH); // Read Positive going Pulse Width Input at D0:
  Duration=Pulsein; // Store Pulse Width, in us., in Duration:
  if(Duration<1250); DigitalWrite(1,LOW); // If Duration less than 1250 us Set D1 Low:
  if(Duration>1750); DigitalWrite(2,LOW); // If Duration greater than 1750 us Set D2 Low:
  if(Duration>=1250); AND if(Duration<=1750); DigitalWrite(1,HIGH);DigitalWrite(2,HIGH); // If Duration between 1250 us and 1750 us Set both D1 and D2 High:
  }

  • Sign in to reply
  • Robert Peter Oakes
    Robert Peter Oakes over 11 years ago in reply to mcb1

    yup, totally agree

     

    I personally only use these pins or the MOSI/MISO/etc ones if i'm running out of other options. I'm sure you already realize this but for those that don't, be aware that not all arduino boards use the same pins for programming / uploading

     

    Some use the MOSI/MISO, some use TX/RX. check your documentation / schematics to be sure for your exact board. If your getting weird behavior with communications back to the  PC, this should be one of your first checks

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to Robert Peter Oakes

    Sorry peter, I should have opened it fully and replied directly, rather than using the preview reply.

     

    Technically it shouldn't matter but it could upset or hang the bootloader, so is worth avoiding unless you have to use it.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Robert Peter Oakes
    Robert Peter Oakes over 11 years ago in reply to mcb1

    You may be correct, I was simply correcting the compile errors not the selection or use of specific pins. I do not know his intended purpose other than what is described here

     

    If he is not using TX/RX then it wont matter but certainly worth the consideration

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to Robert Peter Oakes

    One comment I would add is the use of D0 and D1.

     

    D0 is the Rx pin

    D1 is the Tx pin

     

    see Getting to Know Arduino : Part 1 : Hello, World!

     

     

    You might be better shifting to D2, D3 and D4.

    This would also allow you to use the terminal and send debug information out to the IDE.

     

     

    mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Robert Peter Oakes
    Robert Peter Oakes over 11 years ago

    if(Duration>=1250); AND if(Duration<=1750); DigitalWrite(1,HIGH);DigitalWrite(2,HIGH); // If Duration between 1250 us and 1750 us Set both D1 and D2 High:


    needs to be like this


    if(Duration>=1250 && Duration<=1750)

    {

         DigitalWrite(1,HIGH);

         DigitalWrite(2,HIGH);

    }


    and remove the ";" from after the for statements before the actions


    or you could do this


    if(Duration<1250)  DigitalWrite(1,LOW); // less than 1250

    else if(Duration <1750)  // more than 1250 but less than 1750

         {

              DigitalWrite(1,HIGH);

              DigitalWrite(2,HIGH);

         }

    else DigitalWrite(2,LOW); // everything equal or above 1750



    Oh and you did not post the error message but the above should still fix your problem irrespective


    Happy coding


    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
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