[[戻る>TinyArcade]] *PCとUSB接続で通信 [#b2d62639] PC側でターミナルソフトを9600bpsの設定で起動してTinyArcadeと通信する。~ 今回はRloginというターミナルソフトを使用した。~ http://nanno.dip.jp/ ~ 設定は以下の通り。私の環境ではSocketPortはCOM6でしたが環境によって違うため適当に合わせて下さい。~ #ref(Rlogin1.jpg,,,100%) プログラム側ではUSBDeviceを初期化してSerialUSBを9600bpsに設定。~ SerialUSB.read()でPCからデータを受け取りSerialUSB.writeでPCにデータを送っている 。~ *サンプルプログラム [#c4035a50] #include <stdlib.h> #include <TinyScreen.h> static const int BUTTON_LEFT_PIN = 45; static const int BUTTON_RIGHT_PIN = 44; TinyScreen tiny_screen = TinyScreen(TinyScreenPlus); void setup() { // Initialize serial USBDevice.init(); USBDevice.attach(); SerialUSB.begin(9600); // Initialize screen tiny_screen.begin(); tiny_screen.setBitDepth(TSBitDepth8); tiny_screen.setBrightness(8); tiny_screen.setFont(liberationSansNarrow_12ptFontInfo); tiny_screen.fontColor(TS_8b_White, TS_8b_Black); // Initialize button pinMode(BUTTON_LEFT_PIN, INPUT_PULLUP); pinMode(BUTTON_RIGHT_PIN, INPUT_PULLUP); } void loop() { String cmd = ""; while(SerialUSB.available() > 0) { cmd += static_cast<char>(SerialUSB.read()); } if(!digitalRead(BUTTON_LEFT_PIN)) { SerialUSB.write("push 1 button."); } if(!digitalRead(BUTTON_RIGHT_PIN)) { SerialUSB.write("push 2 button."); } tiny_screen.setCursor(0,0); tiny_screen.print(cmd); } *実行結果 [#t1e812b3] #ref(SerialSample.jpg,,,100%) PCで押した文字が表示される。画面はPC側でdを押した画面。~ #ref(Rlogin2.jpg,,,100%) TinyArcadeでボタンを押した時のPC側のターミナルソフトの画面。~ *サンプルプログラムのダウンロード [#iaada83e] #ref(SerialSample.zip)~