prepare for ESPMegaPRO OOP
This commit is contained in:
parent
51e9f5258a
commit
fc692ef0b0
9 changed files with 266 additions and 71 deletions
|
@ -5,24 +5,19 @@
|
|||
|
||||
// This code demonstrates how to use the cards
|
||||
|
||||
uint8_t pinMap[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 14, 13, 12};
|
||||
|
||||
DigitalInputCard icard = DigitalInputCard(0x21, 0x22);
|
||||
DigitalOutputCard ocard = DigitalOutputCard(0x5F);
|
||||
AnalogCard acard = AnalogCard();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// Instantiate Input Card
|
||||
icard.begin();
|
||||
// Instantiate Output Card
|
||||
ocard.begin();
|
||||
// Instantiate Analog Card
|
||||
acard.begin();
|
||||
// Set output 0 to 4095
|
||||
ocard.analogWrite(0, 4095);
|
||||
void inputCallback(uint8_t pin, bool state) {
|
||||
Serial.print("Input ");
|
||||
Serial.print(pin);
|
||||
Serial.print(" changed to ");
|
||||
Serial.println(state);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
void printInputs() {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
Serial.print("Input ");
|
||||
Serial.print(i);
|
||||
|
@ -30,9 +25,49 @@ void loop() {
|
|||
Serial.print(icard.digitalRead(i));
|
||||
Serial.println();
|
||||
}
|
||||
// Pad the output
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
// Delay for 1 second
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Wire.begin(14, 33);
|
||||
// Instantiate Input Card
|
||||
Serial.println("Initializing Input Card");
|
||||
icard.begin();
|
||||
Serial.println("Initialized Input Card");
|
||||
// Instantiate Output Card
|
||||
Serial.println("Initializing Output Card");
|
||||
ocard.begin();
|
||||
Serial.println("Initialized Output Card");
|
||||
|
||||
icard.loadPinMap(pinMap);
|
||||
|
||||
// Read all the inputs and print them
|
||||
printInputs();
|
||||
|
||||
// Turn on all the outputs
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ocard.digitalWrite(i, true);
|
||||
}
|
||||
|
||||
// Set the debounce time for all inputs to 200ms
|
||||
for (int i = 0; i < 16; i++) {
|
||||
icard.setDebounceTime(i, 200);
|
||||
}
|
||||
|
||||
// Register the callback function
|
||||
icard.registerCallback(inputCallback);
|
||||
}
|
||||
|
||||
unsigned long previousMillis = 0;
|
||||
const unsigned long interval = 1000; // 1 second
|
||||
|
||||
void loop() {
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
printInputs();
|
||||
}
|
||||
icard.loop();
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue