A library for interfacing with the SN74HC595N Shift register. Includes functions for writing bits, bytes, animation and bits at spesified positions.
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:
-
ser Serial data line srclk Data register clock rclk Output register clock oe Output enable (Active Low) reset Reset 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:
-
int array, 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:
-
char array 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:
-
bit 0 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:
-
char output, state
Definition at line 96 of file ShiftOut.cpp.
void writeByte | ( | unsigned char | byte ) |
Writes a byte to the shift register.
- Parameters:
-
byte 0xXX or numbers from 0-255
Definition at line 36 of file ShiftOut.cpp.
Generated on Wed Jul 13 2022 14:06:48 by 1.7.2