A library for interfacing with the SN74HC595N Shift register. Includes functions for writing bits, bytes, animation and bits at spesified positions.

Embed: (wiki syntax)

« Back to documentation index

ShiftOut Class Reference

ShiftOut Class Reference

This is a library for easy interfacing with the SN74HC595N 8-bit Shift Register. More...

#include <ShiftOut.h>

Public Member Functions

 ShiftOut (PinName ser, PinName srclk, PinName rclk, PinName oe, PinName reset)
 Create a ShiftOut interface.
void writeByte (unsigned char)
 Writes a byte to the shift register.
void writeBit (unsigned char)
 Writes a bit to the first output on the shift register.
void animate (int[][8], int, int)
 Writes bits from an 2D array, with configurable delay.
void animationExample (void)
 Demonstrates two animation examples by using the animate function.
void writeBitAtPos (unsigned char, bool)
 Writes the desired state to the output on the shift register.
void writeArray (char[8])
 Writes the corresponding array item to the output on the shift register.

Detailed Description

This is a library for easy interfacing with the SN74HC595N 8-bit Shift Register.

The library includes functions for writing bits, bytes and animation array to the register. The Functions are mainly based for writting 8-bits or one byte and can be moddified to work with multiple shift registers.

 #include "mbed.h"
 #include "ShiftOut.h"
 ShiftOut reg(PA_8, PA_9, PC_7, PB_6, D1);

 int main(){              
    while(1){
     reg.writeBitAtPos(3, 1);
     wait(2);
     reg.writeByte(0x30);
     wait(2);
    }
 }

Definition at line 42 of file ShiftOut.h.


Constructor & Destructor Documentation

ShiftOut ( PinName  ser,
PinName  srclk,
PinName  rclk,
PinName  oe,
PinName  reset 
)

Create a ShiftOut interface.

Parameters:
serSerial data line
srclkData register clock
rclkOutput register clock
oeOutput enable (Active Low)
resetReset line for data register (Active Low) Writing Byte Example:

 #include "mbed.h"
 #include "ShiftOut.h"

 ShiftOut reg(PA_8, PA_9, PC_7, PB_6, D1);
 int main()
 {
     reg.writeByte(0x00); //Writes each bit to the SN74HC595N
     while(1) {
         wait_ms(300);
     }
 }

Definition at line 14 of file ShiftOut.cpp.


Member Function Documentation

void animate ( int  arr[][8],
int  lines,
int  delay_ms 
)

Writes bits from an 2D array, with configurable delay.

Parameters:
intarray, int lines, int delay_ms writes a 2D array with n-lines with a configurable delay in ms

 #include "mbed.h"
 #include "ShiftOut.h"
 ShiftOut reg(PA_8, PA_9, PC_7, PB_6, D1);

 int main(){
   int strobe[][8]= {{1,0,0,0,0,0,0,0},
                    {0,1,0,0,0,0,0,0},
                    {0,0,1,0,0,0,0,0},
                    {0,0,0,1,0,0,0,0},
                    {0,0,0,0,1,0,0,0},
                    {0,0,0,0,0,1,0,0},
                    {0,0,0,0,0,0,1,0},
                    {0,0,0,0,0,0,0,1}};
      while(1){           
          reg.animate(strobe, 8, 200);
      }
  }

Definition at line 51 of file ShiftOut.cpp.

void animationExample ( void   )

Demonstrates two animation examples by using the animate function.

Definition at line 61 of file ShiftOut.cpp.

void writeArray ( char  [8] )

Writes the corresponding array item to the output on the shift register.

Parameters:
chararray writes to the output from a state array
void writeBit ( unsigned char  bit )

Writes a bit to the first output on the shift register.

Parameters:
bit0 or 1

Definition at line 45 of file ShiftOut.cpp.

void writeBitAtPos ( unsigned char  pin,
bool  state 
)

Writes the desired state to the output on the shift register.

Parameters:
charoutput, state

Definition at line 96 of file ShiftOut.cpp.

void writeByte ( unsigned char  byte )

Writes a byte to the shift register.

Parameters:
byte0xXX or numbers from 0-255

Definition at line 36 of file ShiftOut.cpp.