Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.electronics.basics > #52731

Re: Arduino code sources?

Subject Re: Arduino code sources?
Newsgroups sci.electronics.basics, sci.electronics.design
References <pg02fept12fd4h872f8jq590libopp4201@4ax.com>
From bitrex <user@example.net>
Message-ID <Ba0JE.47897$NT5.9760@fx47.iad> (permalink)
Organization frugalusenet - www.frugalusenet.com
Date 2019-06-02 23:08 -0400

Cross-posted to 2 groups.

Show all headers | View raw


On 5/31/19 6:48 AM, Terry Pinnell wrote:
> I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super Starter kit)
> and am stepping through its tutorials. In parallel I'm trying to learn the basics of
> its C++ based programming language, but that's proving a struggle. I'm impatient to
> use Arduino on my own projects so I will take a 'copy/paste/edit' approach. It then
> becomes a matter of finding sketches that cover a particular subject and then
> tailoring.
> 
> I'd therefore appreciate recommendations on Arduino sketch sources that others have
> found useful please.
> 
> Terry, East Grinstead, UK
> 

A "modern C++" feature that would be very helpful for uP based projects 
is a smart pointer. You can't really do dynamic memory 
allocation/de-allocation at will on a processor with 2k of RAM. But you 
still often need to hold and transfer resources around.

What's a pointer? A pointer holds the address of a _resource_. The 
ownership status of a resource must always be well-defined. A "unique 
pointer" object defines ownership of a resource - the object that holds 
that unique pointer object, which wraps a dumb pointer, "owns" that 
resource. Unique pointers cant be copied, only moved. If an object holds 
a unique pointer it cannot be copied, either, or else two owners would 
exist. Nuh uh.

Sometimes other code needs to hold a reference to a resource. Some logic 
would like to see what a data buffer contains, but shouldn't "own" the 
buffer. So there can be an "observer pointer". It can only be used for 
read-only access to the resource but cannot modify the actual resource's 
state in any way. The observer container can be both copied and moved. 
They can be passed to functions, even plain-C functions, taking a 
const-qualified raw pointer seamlessly but cannot be passed to functions 
taking a non-const qualified pointer as that would allow write access to 
the resource.

An advantage of C++ is you can write code to define rule-enforcing data 
structures like that to, by design, self-enforce safer further design 
decisions. Along the same lines raw data types like "int" should never 
be used and passed around to represent something like dollars in a bank 
account, or velocity. They should be wrapped in an object that enforces 
assumptions like class Dollars, or class Velocity. A function that 
computes an output velocity from an input velocity should return a 
Velocity and take a Velocity argument e.g. Velocity 
calc_new_velocity(Velocity v) not int calc_new_velocity(int v).

And no, this almost never "bloats the code" if done intelligently the 
compiler and optimizer will figure out that in almost all cases it can 
compute a velocity under the hood by just manipulating the raw ints like 
it would when compiling C. all the boilerplate is mostly for your 
benefit so it can warn you if you try to do something stupid.

Back to sci.electronics.basics | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Arduino code sources? Terry Pinnell <me@somewhere.invalid> - 2019-05-31 11:48 +0100
  Re: Arduino code sources? Cursitor Doom <curd@notformail.com> - 2019-05-31 11:40 +0000
    Re: Arduino code sources? terrypingm@gmail.com - 2019-05-31 05:57 -0700
      Re: Arduino code sources? Cursitor Doom <curd@notformail.com> - 2019-05-31 19:27 +0000
    Re: Arduino code sources? Peter Percival <peterxpercival@hotmail.com> - 2019-06-12 13:41 +0100
      Re: Arduino code sources? Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2019-06-12 21:48 -0400
        Re: Arduino code sources? Peter Percival <peterxpercival@hotmail.com> - 2019-06-13 17:46 +0100
  Re: Arduino code sources? bitrex <user@example.net> - 2019-05-31 11:37 -0400
    Re: Arduino code sources? bitrex <user@example.net> - 2019-05-31 11:39 -0400
      Re: Arduino code sources? Terry Pinnell <me@somewhere.invalid> - 2019-05-31 18:13 +0100
  Re: Arduino code sources? Ralph Mowery <rmowery28146@earthlink.net> - 2019-05-31 15:07 -0400
  Re: Arduino code sources? Rheilly Phoull <rheilly@bigslong.com> - 2019-06-01 08:13 +0800
  Re: Arduino code sources? S Deyoreo <sdeyoreo@hotmail.com> - 2019-05-31 18:36 -0700
  Re: Arduino code sources? Terry Pinnell <me@somewhere.invalid> - 2019-06-01 11:45 +0100
    Re: Arduino code sources? Tom Gardner <spamjunk@blueyonder.co.uk> - 2019-06-01 12:36 +0100
      Re: Arduino code sources? Terry Pinnell <me@somewhere.invalid> - 2019-06-01 16:04 +0100
    Re: Arduino code sources? Ralph Mowery <rmowery28146@earthlink.net> - 2019-06-01 11:26 -0400
  Re: Arduino code sources? "Rodney Pont" <mlist4@infohit.me.uk> - 2019-06-01 15:11 +0100
    Re: Arduino code sources? Terry Pinnell <me@somewhere.invalid> - 2019-06-01 16:20 +0100
  Re: Arduino code sources? bitrex <user@example.net> - 2019-06-02 23:08 -0400
    Re: Arduino code sources? bitrex <user@example.net> - 2019-06-02 23:40 -0400

csiph-web