Last active
August 16, 2018 10:40
-
-
Save freegroup/8e33129bd64c1336f32c293e2ff60239 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use shift registers(74HC595) to control an insane amount of digital inputs. | |
// https://www.youtube.com/watch?v=nXl4fb_LbcI | |
#include <SPI.h> | |
byte Input, Output, Check=1; | |
int j; | |
void setup(){ | |
pinMode(13, OUTPUT);//clock | |
pinMode(11, OUTPUT);//data | |
pinMode(4, OUTPUT);//latch | |
pinMode(2, INPUT);//Input from buttons | |
SPI.setBitOrder(MSBFIRST); | |
SPI.setDataMode(SPI_MODE0); | |
SPI.setClockDivider(SPI_CLOCK_DIV2); | |
SPI.begin(); | |
SPI.transfer(255); | |
SPI.transfer(0); | |
digitalWrite(4, HIGH); | |
digitalWrite(4, LOW); | |
Serial.begin(9600); | |
attachInterrupt(0, pin_read, RISING); | |
}//setup | |
void loop(){ | |
}//loop | |
void pin_read(){ | |
for(j=0; j<50; j++) | |
delayMicroseconds(1000); | |
Check=1; | |
for(j=0; j<8; j++){ | |
SPI.transfer(Check); | |
SPI.transfer(Output); | |
digitalWrite(4, HIGH); | |
digitalWrite(4, LOW); | |
delayMicroseconds(500); | |
if(digitalRead(2)==HIGH){ | |
if(bitRead(Output, j)==1) | |
bitWrite(Output, j, 0); | |
else | |
bitWrite(Output, j, 1); | |
}//dig check | |
Check = Check<<1; | |
}//j | |
SPI.transfer(255); | |
SPI.transfer(Output); | |
digitalWrite(4, HIGH); | |
digitalWrite(4, LOW); | |
while(digitalRead(2)==HIGH){} | |
}//pin_read | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment