1
0
mirror of https://github.com/gdsports/USBHost_t36 synced 2024-12-22 15:28:53 -05:00
USBHost_t36/examples/Test/Test.ino

81 lines
1.6 KiB
Arduino
Raw Normal View History

2017-03-07 10:40:06 -05:00
// Simple test of USB Host
//
// This example is in the public domain
#include "USBHost_t36.h"
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
KeyboardController keyboard1(myusb);
KeyboardController keyboard2(myusb);
MIDIDevice midi1(myusb);
void setup()
{
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.println("USB Host Testing");
myusb.begin();
2017-03-07 10:47:02 -05:00
keyboard1.attachPress(OnPress);
keyboard2.attachPress(OnPress);
2017-03-07 10:40:06 -05:00
midi1.setHandleNoteOff(OnNoteOff);
midi1.setHandleNoteOn(OnNoteOn);
midi1.setHandleControlChange(OnControlChange);
}
void loop()
{
myusb.Task();
midi1.read();
}
2017-03-07 10:47:02 -05:00
void OnPress(int key)
2017-03-07 10:40:06 -05:00
{
2017-03-07 10:47:02 -05:00
Serial.print("key '");
Serial.print((char)key);
Serial.print("' ");
2017-03-07 10:40:06 -05:00
Serial.println(key);
//Serial.print("key ");
//Serial.print((char)keyboard1.getKey());
//Serial.print(" ");
//Serial.print((char)keyboard2.getKey());
//Serial.println();
}
void OnNoteOn(byte channel, byte note, byte velocity)
{
Serial.print("Note On, ch=");
Serial.print(channel);
Serial.print(", note=");
Serial.print(note);
Serial.print(", velocity=");
Serial.print(velocity);
Serial.println();
}
void OnNoteOff(byte channel, byte note, byte velocity)
{
Serial.print("Note Off, ch=");
Serial.print(channel);
Serial.print(", note=");
Serial.print(note);
//Serial.print(", velocity=");
//Serial.print(velocity);
Serial.println();
}
void OnControlChange(byte channel, byte control, byte value)
{
Serial.print("Control Change, ch=");
Serial.print(channel);
Serial.print(", control=");
Serial.print(control);
Serial.print(", value=");
Serial.print(value);
Serial.println();
}