Categories
Statistics
Flag Counter
Since 08.08.2014
Counts only, if "DNT = disabled".

Your IP is 54.225.42.99
ec2-54-225-42-99.compute-1.a
Info
Valid HTML 4.01 Transitional Creative Commons Lizenzvertrag
rss
เราจะทำแบบวิศวกรผู้ยิ่งใหญ่
We love the King
Your valuable opinion :
5 stars

Avg. 5.00 from 3 votes.



Arduino-Code-Snippets.php   8737 Bytes    01-03-2017 20:49:42


Arduino Genuino Code Snippets


My personal "cloud" storage



As the title suggests this is a collection of self written code to be copy-pasted into future projects. It is likely possible that smarter solutions exist elsewhere ...






#1 HEXDUMP OF AN EEPROM



Double click on code to select ...


/* ////////////////////////////////////////////////////////////////// 
HEXDUMP OF AN EEPROM
http://www.changpuak.ch/electronics/Arduino-Code-Snippets.php
////////////////////////////////////////////////////////////////// */

// Import library for I2C / TWI devices
#include <Wire.h>

// Define eeprom address
const byte I2CADRESSE = 0x50 ;

// In Setup add
Wire.begin();
Serial.begin(9600);  // because data is send to console

// And here comes the function ...
void ReadEeprom()
{
byte rdata ;
  for (int address = 0; address < 512; address+=8) 
  {  
    if ( address < 16 ) Serial.print("0");
    if ( address < 0x100 ) Serial.print("0");
    Serial.print(address,HEX);  
    Serial.print("\t"); 
    // One row, HEX
    for (int add = 0; add < 8; add++) 
    { 
    Wire.beginTransmission(I2CADRESSE); 
    Wire.write((address+add) >> 8);   // MSB
    Wire.write((address+add) & 0xFF); // LSB    
    Wire.endTransmission();  
    Wire.requestFrom(I2CADRESSE,1);
    if (Wire.available()) rdata = Wire.read();
    if (rdata<16) Serial.print("0");  
    Serial.print(rdata, HEX);
    Serial.print(" ");
    }
    Serial.print("\t");
    // One row, ASCII
    for (int add = 0; add < 8; add++) 
    { 
    Wire.beginTransmission(I2CADRESSE);  
    Wire.write((address+add) >> 8);   // MSB
    Wire.write((address+add) & 0xFF); // LSB    
    Wire.endTransmission();  
    Wire.requestFrom(I2CADRESSE,1);
    if (Wire.available()) rdata = Wire.read();
    if (rdata < 32) 
    {
    Serial.print(".");
    }
    else if (rdata > 126) 
       {
       Serial.print(".");
       }
       else
          {
          Serial.print(char(rdata));
          }
    Serial.print(" ");
    }
    Serial.println();  
  } 
  Serial.print("\n");  

Serial.println("\nO.K.\n\n");
}

// ////////////////////////////////////////////////////////////////// 
// END OF FILE.
// ////////////////////////////////////////////////////////////////// 




#2 SERIAL MENUE / COMMAND PARSER



Double click on code to select ...


// ///////////////////////////////////////////////////////////// 
//
//  A MENUE FOR THE SERIAL COMMUNICATION
//  BY ALEXANDER C. FRANK, (C) 2017
//
// ///////////////////////////////////////////////////////////// 

char Buffy[20] ;                 // holds User Input from Serial
byte byteRead ;

// ///////////////////////////////////////////////////////////// 
// Clears the Input Buffer
// ///////////////////////////////////////////////////////////// 
void InitBuffy()
{
  for (int i=0; i<20; i++)
  Buffy[i] = 32 ;   // SPACE
}

// ///////////////////////////////////////////////////////////// 
// Read User Input from Serial
// ///////////////////////////////////////////////////////////// 
void ReadUserInput()
{
  int pointer = 0 ;
  boolean ende = false ;
  while ( ( Serial.available() ) || ( ende == false ) ) 
      {
      byteRead = Serial.read();
      if ( byteRead == 10 ){ ende = true ; }
      if ( byteRead < 255 )		   // YES, ALWAYS TRUE :-)
        { 
        Buffy[pointer] = byteRead ; 
        if ( pointer < 19 ) pointer++ ;
        }
      }
}

// ///////////////////////////////////////////////////////////// 
// Prints a list of Options
// ///////////////////////////////////////////////////////////// 
void print_options()
{
  Serial.print("ARDUINO CONFIGURATION MENUE\n");
  Serial.print("---------------------------\n");
  Serial.print("[0] Execute Function Zero\n");
  Serial.print("[1] Execute Function One\n");
  Serial.print("---------------------------\n");
  Serial.print(">>> PRESS KEY ...\n");
}


void setup() 
{
  Serial.begin(9600);
  print_options();
}

void loop()
{
    InitBuffy();
    ReadUserInput();
    int user_command = Buffy[0] ;               
    
    switch (user_command)
    {
      case 48 : /* 0 */  
        Serial.println("\nFunction '0'.\n"); 
        print_options(); 
        break;
      case 49 : /* 1 */  
        Serial.println("\nFunction '1'.\n"); 
        print_options(); 
        break;
      default:
        Serial.println("\nOOOPS - Invalid Input.\n");
        print_options();
    }
    delay(200);  
}

// ///////////////////////////////////////////////////////////// 
// END OF FILE.
// ///////////////////////////////////////////////////////////// 




✈ Share your thoughts


✈ Nothing more to be seen below this point ? Maybe your browser blocks the facebook iframe.
The webmaster does not read the comments regularly. Urgent questions should be send via email.








 
t1 = 3943 d

t2 = 570 ms

★ ★ ★  Copyright © 2006 - 2017 by changpuak.ch  ★ ★ ★

PRchecker.info Impressum