Hello,
I am trying to read the USB keyboard attached with the MKR Zero USB port to generate interrupt through following program. I have given digital pin number 22/23 to USB port pin. However, the inbuilt LED is not reacting. I have also attached an i2c 16 by 2 LCD.
const byte LED = 32;
const byte BUTTON = 23;
// Require keyboard control library
#include <KeyboardController.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Initialize USB Controller
USBHost usb;
// Attach keyboard controller to USB
KeyboardController keyboard(usb);
// This function intercepts key press
void keyPressed() {
lcd.write(keyboard.getKey());
}
// Interrupt Service Routine (ISR)
void switchPressed ()
{
if (digitalRead (BUTTON) == LOW)
digitalWrite (LED, HIGH);
else
digitalWrite (LED, LOW);
} // end of switchPressed
void setup ()
{
lcd.init();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("Program started");
pinMode (LED, OUTPUT); // so we can update the LED
digitalWrite (BUTTON, HIGH); // internal pull-up resistor
attachInterrupt (digitalPinToInterrupt (BUTTON), switchPressed, CHANGE); // attach interrupt handler
} // end of setup
void loop ()
{
usb.Task();
// loop doing nothing
}
This is a part of a bigger project on which I have been working for several months. Any help is greatly appreciated.
The USB pin number I got from here -
variant1.txt (19.0 KB)
Thanks, and Regards.