card installation checking
This commit is contained in:
parent
1862887d30
commit
1481c08d3a
10 changed files with 122 additions and 37 deletions
|
@ -5,19 +5,21 @@
|
|||
|
||||
// This code demonstrates how to use the cards
|
||||
|
||||
|
||||
ESPMegaPRO espmega = ESPMegaPRO();
|
||||
AnalogCard analogCard = AnalogCard();
|
||||
|
||||
void inputCallback(uint8_t pin, bool state) {
|
||||
void inputCallback(uint8_t pin, bool state)
|
||||
{
|
||||
Serial.print("Input ");
|
||||
Serial.print(pin);
|
||||
Serial.print(" changed to ");
|
||||
Serial.println(state);
|
||||
}
|
||||
|
||||
void printInputs() {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
void printInputs()
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Serial.print("Input ");
|
||||
Serial.print(i);
|
||||
Serial.print(": ");
|
||||
|
@ -26,37 +28,49 @@ void printInputs() {
|
|||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
void setup()
|
||||
{
|
||||
// Instantiate ESPMega
|
||||
espmega.begin();
|
||||
Serial.println("ESPMega initialized");
|
||||
// Read all the inputs and print them
|
||||
printInputs();
|
||||
// Turn on all the outputs
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
espmega.outputs.digitalWrite(i, true);
|
||||
}
|
||||
// Set the debounce time for all inputs to 200ms
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
espmega.inputs.setDebounceTime(i, 200);
|
||||
}
|
||||
// Register the callback function
|
||||
espmega.inputs.registerCallback(inputCallback);
|
||||
|
||||
// Install the analog card
|
||||
espmega.installCard(0, &analogCard);
|
||||
Serial.println("Installing analog card");
|
||||
if (espmega.installCard(0, &analogCard))
|
||||
{
|
||||
Serial.println("Analog card installed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Failed to install analog card");
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long previousMillis = 0;
|
||||
const unsigned long interval = 1000; // 1 second
|
||||
|
||||
void loop() {
|
||||
void loop()
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
if (currentMillis - previousMillis >= interval)
|
||||
{
|
||||
previousMillis = currentMillis;
|
||||
printInputs();
|
||||
}
|
||||
espmega.loop();
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue