• 車種別
  • パーツ
  • 整備手帳
  • ブログ
  • みんカラ+

まう@朱理のブログ一覧

2021年02月02日 イイね!

ジムカーナタイム測定機6

Seeeduino XiaoはArduinoのプログラムでいけるので、まずはWikiを確認してArduino IDEをセットアップ
Seeeduino Xiaoをはじめよう
キーボードとして使いたかったのでSeeeduino XIAOをUSBデバイス(TinyUSB)として使うを設定
スケッチ例から→AdafruitTinyUSBLibrary→HID→hid_compositeを選択
これを確認すると、HID_USAGE_CONSUMER_VOLUME_DECREMENT=音量キーダウンの記載があったので、コードをコピペ変更して音量キーアップにして、他のいらない部分を消しました。
D0を音量キーアップ(0x00E9)、今後使うかもしれないのでD1を音量キーダウン(0x00EA)に設定して、コンパイル→書込で完成です。
Seeeduino Xiaoには3.3VのDCDCコンバーター(XC6206P332MR)が内蔵されているようで、ICのデータシート確認して200mAまで出せるのでDCDCを一つ省略できそうでした。
USB-Cから給電する5Vがそのまま取り出せるので5V系も動かせます。
というかSPI、I2C、UARTなどもついているので、これだけで全部こなせそうな勢いですね。
タッチディスプレイ追加して、ストップウオッチ表示できるように組み込めば。。。(そんなプログラム書けませんが)


以下スケッチ例コピペ
<pre>
/*********************************************************************
 Adafruit invests time and resources providing this open source code,
 please support Adafruit and open-source hardware by purchasing
 products from Adafruit!

 MIT license, check LICENSE for more information
 Copyright (c) 2019 Ha Thach for Adafruit Industries
 All text above, and the splash screen below must be included in
 any redistribution
*********************************************************************/

#include "Adafruit_TinyUSB.h"

#if defined ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS
const int pin = 4; // Left Button
bool activeState = true;
#elif defined ARDUINO_NRF52840_FEATHER
const int pin = 7; // UserSw
bool activeState = false;
#else
//const int pin = 12;
const int pin = 0;
const int pin2 = 1;
bool activeState = false;
#endif


// Report ID
enum
{
 RID_KEYBOARD = 1,
 RID_MOUSE,
 RID_CONSUMER_CONTROL, // Media, volume etc ..
};

// HID report descriptor using TinyUSB's template
uint8_t const desc_hid_report[] =
{
 TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(RID_KEYBOARD) ),
 TUD_HID_REPORT_DESC_MOUSE   ( HID_REPORT_ID(RID_MOUSE) ),
 TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(RID_CONSUMER_CONTROL) )
};

// USB HID object
Adafruit_USBD_HID usb_hid;

// the setup function runs once when you press reset or power the board
void setup()
{
 usb_hid.setPollInterval(2);
 usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
 //usb_hid.setStringDescriptor("TinyUSB HID Composite");

 usb_hid.begin();

 // Set up button, pullup opposite to active state
 pinMode(pin, activeState ? INPUT_PULLDOWN : INPUT_PULLUP);
 pinMode(pin2, activeState ? INPUT_PULLDOWN : INPUT_PULLUP);

 Serial.begin(115200);
 Serial.println("Adafruit TinyUSB HID Composite example");

 // wait until device mounted
 while ( !USBDevice.mounted() ) delay(1);
}

void loop()
{
 // poll gpio once each 1 ms
 delay(1);

 // Whether button is pressed
 bool btn_pressed = (digitalRead(pin) == activeState);
 bool btn_pressed2 = (digitalRead(pin2) == activeState);
 // Remote wakeup
 if ( USBDevice.suspended() && btn_pressed )
 {
   // Wake up host if we are in suspend mode
   // and REMOTE_WAKEUP feature is enabled by host
   USBDevice.remoteWakeup();
 }
 if ( USBDevice.suspended() && btn_pressed2 )
 {
   // Wake up host if we are in suspend mode
   // and REMOTE_WAKEUP feature is enabled by host
   USBDevice.remoteWakeup();
 }

 /*------------- Consumer Control -------------*/
 if ( usb_hid.ready() )
 {
   // Consumer Control is used to control Media playback, Volume, Brightness etc ...
   // Consumer report is 2-byte containing the control code of the key
   // For list of control check out https://github.com/hathach/tinyusb/blob/master/src/class/hid/hid.h#L544

   // use to send consumer release report
   static bool has_consumer_key = false;

   if ( btn_pressed )
   {
     // send volume up (0x00E9)
     usb_hid.sendReport16(RID_CONSUMER_CONTROL, HID_USAGE_CONSUMER_VOLUME_INCREMENT);
     has_consumer_key = true;
   } else
   {
     // release the consume key by sending zero (0x0000)
     if (has_consumer_key) usb_hid.sendReport16(RID_CONSUMER_CONTROL, 0);
     has_consumer_key = false;
   }
 }

 /*------------- Consumer Control -------------*/
 if ( usb_hid.ready() )
 {
   // Consumer Control is used to control Media playback, Volume, Brightness etc ...
   // Consumer report is 2-byte containing the control code of the key
   // For list of control check out https://github.com/hathach/tinyusb/blob/master/src/class/hid/hid.h#L544

   // use to send consumer release report
   static bool has_consumer_key = false;

   if ( btn_pressed2 )
   {
     // send volume down (0x00EA)
     usb_hid.sendReport16(RID_CONSUMER_CONTROL, HID_USAGE_CONSUMER_VOLUME_DECREMENT);
     has_consumer_key = true;
   } else
   {
     // release the consume key by sending zero (0x0000)
     if (has_consumer_key) usb_hid.sendReport16(RID_CONSUMER_CONTROL, 0);
     has_consumer_key = false;
   }
 }
}

</pre>
Posted at 2021/02/02 02:54:32 | コメント(0) | トラックバック(0) | RC | 日記
2012年02月14日 イイね!

ラジコンプロポを新調!



実車じゃないですが、ラジコンカーのプロポを新調!
KOプロポのNewEX-1
デザインはアレですがw
Posted at 2012/02/14 21:06:52 | コメント(0) | トラックバック(0) | RC | 日記

プロフィール

まう@朱理です。よろしくお願いします。
みんカラ新規会員登録

ユーザー内検索

<< 2025/8 >>

     12
3456789
10111213141516
17181920212223
24252627282930
31      

リンク・クリップ

NDロードスターのリヤバンパーの穴の件 
カテゴリ:その他(カテゴリ未設定)
2021/01/10 00:36:03

愛車一覧

マツダ ロードスター マツダ ロードスター
2020/04/01納車 マシーングレープレミアムメタリック
マツダ デミオ マツダ デミオ
12/4納車されました。 2020/04/01乗り換え 155003km
ホンダ CR-Z ホンダ CR-Z
α Blacklabel 9月18日納車でした
ホンダ シビックタイプR ホンダ シビックタイプR
初購入の車でした。 間瀬サーキット 1'17.792 Best

過去のブログ

2021年
01月02月03月04月05月06月
07月08月09月10月11月12月
2020年
01月02月03月04月05月06月
07月08月09月10月11月12月
2019年
01月02月03月04月05月06月
07月08月09月10月11月12月
2018年
01月02月03月04月05月06月
07月08月09月10月11月12月
2017年
01月02月03月04月05月06月
07月08月09月10月11月12月
2016年
01月02月03月04月05月06月
07月08月09月10月11月12月
2015年
01月02月03月04月05月06月
07月08月09月10月11月12月
2014年
01月02月03月04月05月06月
07月08月09月10月11月12月
2013年
01月02月03月04月05月06月
07月08月09月10月11月12月
2012年
01月02月03月04月05月06月
07月08月09月10月11月12月
2011年
01月02月03月04月05月06月
07月08月09月10月11月12月
ヘルプ利用規約サイトマップ
© LY Corporation