Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef ExternalIO_h
- #define ExternalIO_h
- #define DEBOUNCEE 150
- unsigned long previousMilliss = 0;
- int InterruptPIN = 17;
- boolean keyChanged = false;
- void InterruptOnIn(){keyChanged = true;}
- PCF8574 ExtOuts(0x20);
- PCF8574 ExtIns(0x21);
- static const inline void Setup_Expanders(){
- for(int i=0;i<8;i++) {ExtOuts.pinMode(i, OUTPUT);}
- ExtOuts.begin();
- pinMode(InterruptPIN, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(InterruptPIN), InterruptOnIn, FALLING);
- for(int i=0;i<8;i++) {ExtIns.pinMode(i, INPUT);}
- ExtIns.begin();
- Wire.beginTransmission(0x21);
- Wire.write(0xFF);
- Wire.endTransmission(true);
- for(int i=0;i<8;i++) {ExtOuts.digitalWrite(i, HIGH);delay(100);}
- for(int i=8;i>=0;i--) {ExtOuts.digitalWrite(i, LOW);delay(100);}
- }
- static const inline void Expander_Loop(){
- if (keyChanged){
- unsigned long currentMilliss = millis();
- if (currentMilliss - previousMilliss < DEBOUNCEE){return;}
- PCF8574::DigitalInput val = ExtIns.digitalReadAll();
- if (val.p0==HIGH){
- if(ExtOuts.digitalRead(P0) == LOW){
- ExtOuts.digitalWrite(P0, HIGH);
- }else{
- ExtOuts.digitalWrite(P0, LOW);
- }
- }
- if (val.p1==HIGH) {
- if(ExtOuts.digitalRead(P1) == LOW){
- ExtOuts.digitalWrite(P1, HIGH);
- }else{
- ExtOuts.digitalWrite(P1, LOW);
- }
- }
- if (val.p2==HIGH) {
- if(ExtOuts.digitalRead(P2) == LOW){
- ExtOuts.digitalWrite(P2, HIGH);
- }else{
- ExtOuts.digitalWrite(P2, LOW);
- }
- }
- if (val.p3==HIGH) {
- if(ExtOuts.digitalRead(P3) == LOW){
- ExtOuts.digitalWrite(P3, HIGH);
- }else{
- ExtOuts.digitalWrite(P3, LOW);
- }
- }
- if (val.p4==HIGH) {
- if(ExtOuts.digitalRead(P4) == LOW){
- ExtOuts.digitalWrite(P4, HIGH);
- }else{
- ExtOuts.digitalWrite(P4, LOW);
- }
- }
- if (val.p5==HIGH) {
- if(ExtOuts.digitalRead(P5) == LOW){
- ExtOuts.digitalWrite(P5, HIGH);
- }else{
- ExtOuts.digitalWrite(P5, LOW);
- }
- }
- if (val.p6==HIGH) {
- if(ExtOuts.digitalRead(P6) == LOW){
- ExtOuts.digitalWrite(P6, HIGH);
- }else{
- ExtOuts.digitalWrite(P6, LOW);
- }
- }
- if (val.p7==HIGH) {
- if(ExtOuts.digitalRead(P7) == LOW){
- ExtOuts.digitalWrite(P7, HIGH);
- }else{
- ExtOuts.digitalWrite(P7, LOW);
- }
- }
- keyChanged = false;
- previousMilliss = currentMilliss;
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement