-
-
Notifications
You must be signed in to change notification settings - Fork 219
Open
Description
I have an Opta Lite and am trying to use the digital inputs from the M4 processor, but have found a problem reading A0 (PA0_C) and A1 (PC2_C ). As an example, the code below to debounce the inputs and switch the relays works fine on the M7, but on the M4 it only works with inputs A2 to A7, A0 & A1 do nothing. Note that the only code on the other processor during the test is an RPC.begin();
Any assistance would be greatly appreciated.
#include <RPC.h>
const byte switches = 4;
int switchinput[] = {A0, A1, A2, A3};
bool currentstatus[] = {LOW, LOW, LOW, LOW};
bool laststatus[] = {LOW, LOW, LOW, LOW};
unsigned long lastbouncetime[] = {0, 0, 0, 0};
int relayoutput[] = {RELAY1, RELAY2, RELAY3, RELAY4};
int statusled[] = {LED_D0, LED_D1, LED_D2, LED_D3};
bool outputstatus[] = {LOW, LOW, LOW, LOW};
int debouncedelay = 50;
unsigned long currentlooptime;
void setup() {
RPC.begin();
// initialise inputs & outputs
for(byte loop=0; loop<switches; loop++)
{
pinMode(switchinput[loop], INPUT);
pinMode(relayoutput[loop], OUTPUT);
pinMode(statusled[loop], OUTPUT);
digitalWrite(relayoutput[loop], outputstatus[loop]);
digitalWrite(statusled[loop], outputstatus[loop]);
}
}
void loop() {
currentlooptime=millis();
for(byte switchnum=0; switchnum<switches; switchnum++)
{
currentstatus[switchnum]=digitalRead(switchinput[switchnum]);
// debounce the input
if(currentstatus[switchnum] != laststatus[switchnum])
{
lastbouncetime[switchnum] = currentlooptime;
laststatus[switchnum] = currentstatus[switchnum];
}
// change the output after the input has finished bouncing
if(currentlooptime - debouncedelay >= lastbouncetime[switchnum] && currentstatus[switchnum] != outputstatus[switchnum])
{
outputstatus[switchnum] = currentstatus[switchnum];
digitalWrite(relayoutput[switchnum], outputstatus[switchnum]);
digitalWrite(statusled[switchnum], outputstatus[switchnum]);
}
}
}Metadata
Metadata
Assignees
Labels
No labels