Arduino Night

From Unallocated Space
Revision as of 10:57, 5 April 2013 by Calc (talk | contribs)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

External code links

Various code snippets used during class - http://pastebin.com/u/uas_arduino

Random Code

  • Writing an arbitrary number of bits to pins
  byte pins[] = {2,3,4,5,6,7};
  byte totalPins = 6;
  
  void setup(){
     for(byte a = 0; a < totalPins; a++){
        pinMode(pins[a], OUTPUT);
     }
  }
  
  void writeData(byte data, byte numberOfBits, byte startBit){
     for(byte a = startBit; a < numberOfBits; a++){
        if((data >> a) & 0x01){
           digitalWrite(pins[a], HIGH);
        }else{
           digitalWrite(pins[a], LOW);
        }
     }
  }