Skip to content

Instantly share code, notes, and snippets.

@e-Gizmo
Last active December 30, 2015 10:59
Show Gist options
  • Save e-Gizmo/7819565 to your computer and use it in GitHub Desktop.
Save e-Gizmo/7819565 to your computer and use it in GitHub Desktop.
/*Output Expander Module
This program converts a serial into a parallel output with 8 output ports per board.
Each output ports has LED state indicators.
+3.3V or +5V of the microcontroller may be used.
This module is usually used with an input expander module.
JP2 pin assignments:
Din on digital pin 8
Str on digital pin 9
Clk on digital pin 10
VDD on +5V
Codes by:
Dan
eGizmo Mechatronix Central
Manila, Philippines
April 3, 2013
*/
// Constants
const int DataIN = 8;
const int StrIN = 9;
const int ClkIN = 10;
void setup()
{
pinMode(DataIN, OUTPUT); // Pin 8 as output
pinMode(ClkIN, OUTPUT); // Pin 9 as output
pinMode(StrIN, OUTPUT); // Pin 10 as output
}
void loop()
{
for(int i = 0; i<=256; i++)
{
shiftOut(i);
// Set cycle for strobe in
digitalWrite(StrIN, HIGH);
digitalWrite(StrIN,LOW);
delay(500);
}
}
void shiftOut(byte DataOUT) // Sets a byte called DataOUT
{
boolean state;
// Sets the cycle for data in and clock in
digitalWrite(DataIN, LOW);
digitalWrite(ClkIN, LOW);
for (int i=0; i<=7; i++)
// This is set for 8bit binary.
{
digitalWrite(ClkIN, LOW);
if (DataOUT&(1<<i))
{
state = HIGH;
}
else
{
state = LOW;
}
digitalWrite(DataIN, state);
digitalWrite(ClkIN, HIGH);
}
digitalWrite(ClkIN,LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment