Differences between revisions 3 and 4
Revision 3 as of 2021-04-07 13:19:48
Size: 2203
Editor: bsw388
Comment:
Revision 4 as of 2021-04-07 13:24:50
Size: 2048
Editor: bsw388
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from AJMGrpOnly/teaching/arduino-pi/projects/arduino/programming
## page was renamed from ajm/teaching/arduino-pi/projects/arduino/programming
#acl apw185:read,write,delete Known:read All:
#acl +All:read apw185:read,write,delete Known:read All:

Programming the Arduino

This is a collection of links and tips on how to program the Arduino. Main source is the Arduino.cc Code Library.

Push buttons

Sound Generation

Fast Division

fast division by 10

Fast division by 10

void divmod10(uint32_t in, uint32_t &div, uint32_t &mod)
{
  uint32_t x=(in>>1); // div = in/10 <==> div = ((in/2)/5)
        uint32_t q=x;

        q= (q>>8) + x;
        q= (q>>8) + x;
        q= (q>>8) + x;
        q= (q>>8) + x + 1;

        x= q;
        q= (q>>1) + x;
        q= (q>>3) + x;
        q= (q>>1) + x;

        div = (q >> 3);
        mod = in - (((div << 2) + div) << 1);
}

This was the earlier version:

Fast division by 10 early version

void divmod10(uint32_t in, uint32_t &div, uint32_t &mod)
{
  // q = in * 0.8;
  uint32_t q = (in >> 1) + (in >> 2);
  q = q + (q >> 4);
  q = q + (q >> 8);
  q = q + (q >> 16);  // not needed for 16 bit version

  // q = q / 8;  ==> q =  in *0.1;
  q = q >> 3;
  
  // determine error
  uint32_t  r = in - ((q << 3) + (q << 1));   // r = in - q*10; 
  div = q + (r > 9);
  if (r > 9) mod = r - 10;
  else mod = r;
}

Home Automation

Doing Two things at Once

Logic Probe

AJMPublic/teaching/arduino-pi/projects/arduino/programming (last edited 2021-04-14 13:17:38 by apw109)