Main Menu

search

You are here

Arduino programming using IDE:

[last updated: 2024-08-02]
Arduino home page
(link to:) Arduino Programming Reference
-----


      On This Page:
  • Programming I/O
  • Data Types:
    • Arrays
    • int
    • short
    • long
    • unsigned long
    • Struct
    • Conversion between data types:
  • Functions
  • Flow Control statements:
  • Text & Character manipulations:
  • Logic statements:
  • Math Operations:
  • Capture program code for websites/forums:

  • Misc programming concepts:
    • eeprom read/write
    • wait for keyboard input
    • float/int data-type weirdness:
    • PWM programming
    • switch input - touch sense and debounce
    • pointers


-----------------------------------------------------------------------

  • Programming I/O:
    • Best procedure is to first define a variable for the pin number you're using (in globals):
        int pinNum = 4;
    • Set the pin as input or output (in setup):
        pinMode(pinNum, OUTPUT); (or "INPUT")

    -----------------------------------------------------------------------

  • Data Types:
    • Arrays

      array of strings:
      String paramList[3] = {"lat", "lng", "alt"};
      https://forum.arduino.cc/t/a-true-array-of-strings-heres-how-i-did-it-us...

    • int (integer):
      2 bytes (16 bits)
      "signed" values ranging from -32,768 - +32767, stored as "2's complement"
      Due and SAMD boards use 4 bytes for int type, with corresponding greater range.
    • short:
      short is a 16-bit (2 byte) data type
    • long:
      4 bytes (32 bits)
      stores integers in range from -2,147,483,648 to +2,147,483,647
    • unsigned long:
      32 bits (4 bytes)
      "unsigned" = no negative value flag, so all of 32 bits used for data, so
      max size = 232 - 1 = 4,294,967,295
          (if storing ms from millis(), this is about 50 days)
    • Struct - Custom data types:
      • Allows you to create a data type that contains multiple parameters, each with its own data type
      • Put the definition/configuration into globals like this:
          Struct person {
                String firstName;
                String lastName;
                int age;
          }

        In this example "person" is the name of the struct data type, while firstName, lastName, and age are the elements of person, and each of them is defined with their respective data types (ie. String and int).

      • In globals, after you've created the person struct, you can create instances of it like this:
          person ID1 (
                "John",
                "Smith",
                47,
          }

        Or: person ID1 = {"John", "Smith", 47};

      • Now you can refer to a given element like this: ID1.firstName or ID1.age.
        You can set or retrieve given data elements using that syntax.
    • Conversion between data types:
      • Convert int to String:
        String newString = String(oldInt);

      ----------------------

    -----------------------------------------------------------------------

  • Functions:
  • Flow Control statements:
  • Text & Character manipulations:
  • Logic statements:
  • Math Operations:
  • tone() function:
    • syntax:
      tone(pin, frequency, duration)
    • where: pin = int of output pin
      freq = Hz as unsigned int (31 Hz minimum)
      duration = in ms as unsigned long

  • Capture program code for website:
    • In IDE, Edit -> Copy for Forum
    • Open text doc and paste copied program text into it
    • Save text file and upload to server (BlueHost at this time)
    • Make link on desired page to open the saved file, with code eg:
        <a target="_blank" href="/sites/default/files/files/OLED-UNO-06.ino.txt">OLED-UNO-06.ino</a>

    -----------------------------------------------------------------------

  • Misc programming concepts:
    • eeprom read/write
    • wait for keyboard input
    • float/int data-type weirdness:
    • PWM programming
    • switch input - touch sense and debounce
    • pointers:

    ----------------------

.

.

.

eof