const byte PIN_DATA    = 2; // pin 2   13    D10     Outpu Signal Data   
const byte PIN_LATCH   =  4; // pin 3   12    D9      Outpu Signal Latch    
const byte PIN_CLOCK   =  3; // pin 5   11    D8      Outpu Signal Clock
const byte PIN_START   =  7;


uint32_t endianConv(uint32_t dword) {
    return ((dword>>24)&0x000000FF) | ((dword>>8)&0x0000FF00) 
    | ((dword<<8)&0x00FF0000) | ((dword<<24)&0xFF000000);
 }

// 2 2E 56 E1
void toBigE(uint8_t *ptr) {
    byte x = ptr[0]; // x = 2
    ptr[0] = ptr[3];
    ptr[3] = x;
    x = ptr[1]; // x 2e
    ptr[1] = ptr[2];
    ptr[2] = x;

}

// Semplice operazione matematica 78
// Conversione ascii/decimale/byte 151

void setup() {
  byte rx[] = {2, 48, 48, 51, 54, 53, 57, 51, 52, 57, 13, 10, 3};

  byte rxHEX[] = {0x02, 0x30, 0x30, 0x33, 0x36, 0x35, 0x39, 0x33, 0x34, 0x39, 0x0D, 0x0A, 0x03};
  
  Serial.begin(9600);
  

  uint16_t a = 66;
  int32_t result = (long)a * 1000;
  Serial.println(result);
  Serial.println(1.0 / 10);



  int16_t qmille = 40*1000;
  long x = ((40u*1000)/3)/255ul;
  Serial.println(x);
  int v = 40000/3/255UL;
  Serial.println(v);


  uint16_t valore = 171 | (170 << 8);
  uint16_t addr_di_valore = (uint16_t)&valore;
  Serial.print("addr di valore : ");
  Serial.println(addr_di_valore);
  byte *ptr_to_2294 = (byte *)addr_di_valore;
  Serial.print(*(ptr_to_2294));
  Serial.print(" ");
  Serial.print(*(ptr_to_2294+1));
  Serial.println();
   
  
  for (byte i=0; i<sizeof(rx); i++) {
      Serial.print(rxHEX[i]);
  }
  Serial.println();
  Serial.print("byte rxHEX[] = {");
  for (byte i=0; i<sizeof(rx); i++) {
      Serial.print("0x");
      if (rx[i] < 0x0F) {
          Serial.print("0");
      }
      Serial.print(rx[i], HEX);
      if (i < (sizeof(rx) - 1))
          Serial.print(", ");
  }
  Serial.println("};");

  Serial.print("byte rx[] = {");
  for (byte i=0; i<sizeof(rx); i++) {
            
      Serial.print(rx[i]);
      if (i < (sizeof(rx) - 1))
          Serial.print(", ");
  }
  Serial.println("};");
  uint32_t vin = 0x22E56E1;
  Serial.println(endianConv(vin), HEX);
  toBigE((uint8_t*)&vin);
  Serial.println(vin, HEX);
  Serial.println(endianConv(vin), HEX);
  uint16_t zu = 43691;
  Serial.print("&zu = ");
  Serial.println((uint16_t)&zu);
  byte *ptr = (byte*)&zu;
  Serial.println((uint16_t)ptr);
  Serial.println(*ptr);
  Serial.println((uint16_t)ptr+1);
  Serial.println(*(ptr+1));


  /*uint32_t bo = (bh & 0xffffff) << 24;
  bh = bh >> 8;*/
  
  //Serial.println(bo);

}

void loop() { 
    
}
74HC595