1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #include "Arduino.h"
- #include "PCF8574.h"
- int encoderPinA = P0;
- int encoderPinB = P1;
- #define INTERRUPTED_PIN D7
- void ICACHE_RAM_ATTR updateEncoder();
- PCF8574 pcf8574(0x38, INTERRUPTED_PIN, updateEncoder);
- volatile long encoderValue = 0;
- uint8_t encoderButtonVal = HIGH;
- void setup()
- {
- Serial.begin (9600);
- delay(500);
-
- pcf8574.encoder(encoderPinA, encoderPinB);
-
- pcf8574.pinMode(P2, INPUT);
-
- Serial.print("Init pcf8574...");
- if (pcf8574.begin()){
- Serial.println("OK");
- }else{
- Serial.println("KO");
- }
- }
- bool changed = false;
- void loop()
- {
- if (changed){
- Serial.print("ENCODER --> ");
- Serial.print(encoderValue);
- Serial.print(" - BUTTON --> ");
- Serial.println(encoderButtonVal?"HIGH":"LOW");
- changed = false;
- }
- }
- bool valPrecEncoderButton = LOW;
- void updateEncoder(){
- changed = pcf8574.readEncoderValue(encoderPinA, encoderPinB, &encoderValue);
-
- encoderButtonVal = pcf8574.digitalRead(P2);
- if (encoderButtonVal!=valPrecEncoderButton){
- changed = true;
- valPrecEncoderButton = encoderButtonVal;
- }
- }
|