eChO.cpp

Another example of traditional byte-by-byte serial communications. This sketch opens the NorthFace for traditional serial at 57600 baud 8N1, and just echoes back everything it reads -- except every other alphabetic charater has iT's CaSe InVeRtEd. so We CaN eAsIlY tElL tHaT iT's WoRkInG.

// Echo sketch, inverting capitalization of alternate alphabetics

void setup() {
  NorthFace.begin(57600); // Start traditional serial on North at 57600 baud 8N1
}

bool flipCase = false;          // A variable to remember if we should change case

void loop() { 
  int ch;

  ch = NorthFace.read();        // Returns -1 if no input

  if (ch >= 0) {                // Got something!

    if ((ch >= 'a' && ch <= 'z') ||  // If ch is a lowercase alphabetic, or..
        (ch >= 'A' && ch <= 'Z')) { // ..an uppercase alphabetic  

      flipCase = !flipCase;     // Toggle our 'state variable'
      if (flipCase)             // If we should case-flip this alphabetic character..
        ch ^= 0x20;             // Wow!  Inverts case by flipping one bit!
    }

    NorthFace.print(ch,BYTE);   // Echo back (possibly modified) character
  }
}

Generated on Fri Apr 22 06:54:10 2011 for SFB by doxygen 1.5.9