Thread: programing the arduino

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    662

    programing the arduino

    as yet i haven't got the arduino its on order. however i have been looking at videos and books.

    it seams to me that a lot of the code for setting up the various boards is done globally ie
    Code:
    int sensor_pin = 8
    
    void setup()
    {
    //stuff here
    }
    
    void loop()
    {
    //more code here
    }
    does it have to be done this way or is it sloppy practice
    coop

  2. #2
    Registered User
    Join Date
    May 2019
    Posts
    203
    In embedded work like this there is usually some configuration of the device, often about what sensor or device is plugged into which port. For a particular physical configuration that basically represents a concept (or set of concepts) from the real world wiring of the device which does apply globally to the code operating the device, so it's typical.

    It may be nicer to organize these globals into a struct, so there's technically just one global object (struct), but that's just a technical difference with the potential positive twist that one might substitute configurations at runtime.

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,850
    That's how you do it with an Arduino

    There is a setup where you setup the device - Things like interrupts, UART, pin I/O, data that you are going to use, ...

    After that you have the "Loop" - When you do an embedded project with a small device you put your project logic here. It will repeat forever.

    It will help you to think of the Arduino code like this...

    Code:
    int main(void) 
    {
      Setup();
    
      for(;;) 
      {
        Loop();
      } 
    
      return 0;
    }
    This sort of blueprint is what most embedded free-standing c programmes do: Setup and Loop. Arduino just formalises it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C and Arduino
    By bamwels in forum C Programming
    Replies: 11
    Last Post: 08-21-2013, 09:20 PM
  2. help in c communication with arduino
    By kapustelis in forum C Programming
    Replies: 8
    Last Post: 02-06-2013, 02:35 AM
  3. arduino
    By Annonymous in forum Tech Board
    Replies: 7
    Last Post: 05-29-2012, 11:13 PM
  4. Arduino LED Clock
    By qtip2293 in forum C++ Programming
    Replies: 1
    Last Post: 10-11-2011, 02:05 PM
  5. Arduino programming
    By Terese in forum C++ Programming
    Replies: 5
    Last Post: 12-11-2010, 01:03 PM

Tags for this Thread