檢視 裁線條碼亮燈 的原始碼
←
裁線條碼亮燈
跳至導覽
跳至搜尋
由於以下原因,您無權編輯此頁面:
您請求的操作只有這個群組的使用者能使用:
使用者
您可以檢視並複製此頁面的原始碼。
==20190104== <c> //20190104增加流水燈 #include <usbhid.h> #include <usbhub.h> #include <hiduniversal.h> #include <hidboot.h> #include <SPI.h> #include <FastLED.h> #define NUM_LEDS 60 // led灯数量 #define DATA_PIN 6 // 数据传输引脚(Digital 6) #define BRIGHTNESS 25 //設定led亮度 int LIGHTDELAY= 60/NUM_LEDS/60; String s; CRGB leds[NUM_LEDS]; class MyParser : public HIDReportParser { public: MyParser(); void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); protected: uint8_t KeyToAscii(bool upper, uint8_t mod, uint8_t key); virtual void OnKeyScanned(bool upper, uint8_t mod, uint8_t key); virtual void OnScanFinished(); }; MyParser::MyParser() {} void MyParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { // If error or empty, return if (buf[2] == 1 || buf[2] == 0) return; for (uint8_t i = 7; i >= 2; i--) { // If empty, skip if (buf[i] == 0) continue; // If enter signal emitted, scan finished if (buf[i] == UHS_HID_BOOT_KEY_ENTER) { OnScanFinished(); } // If not, continue normally else { // If bit position not in 2, it's uppercase words OnKeyScanned(i > 2, buf, buf[i]); } return; } } uint8_t MyParser::KeyToAscii(bool upper, uint8_t mod, uint8_t key) { // Letters if (VALUE_WITHIN(key, 0x04, 0x1d)) { if (upper) return (key - 4 + 'A'); else return (key - 4 + 'a'); } // Numbers else if (VALUE_WITHIN(key, 0x1e, 0x27)) { return ((key == UHS_HID_BOOT_KEY_ZERO) ? '0' : key - 0x1e + '1'); } if(key== 55 ) { return 46; }else return 0; } void MyParser::OnKeyScanned(bool upper, uint8_t mod, uint8_t key) { uint8_t ascii = KeyToAscii(upper, mod, key); // Serial.print((char)ascii); delay(100); s= s + ((char)ascii) + ""; } void MyParser::OnScanFinished() { int i,k,j=2; float a=s.toFloat(); a=a*60; int uplimit=ceil(a)-1; int downlimit=floor(a)-1; //Serial.println(uplimit); FastLED.clear(); for(i=1;i< downlimit;i++){ leds[i] = CRGB::Yellow; FastLED.show(); delay(LIGHTDELAY); FastLED.clear(); } if(uplimit==downlimit){ leds[uplimit] = CRGB::White; }else{ leds[uplimit] = CRGB::Red; // 设置第1个led灯的颜色Red leds[downlimit] = CRGB::Green; // 设置第2个led灯的颜色Red } FastLED.show(); s=""; } USB Usb; USBHub Hub(&Usb); HIDUniversal Hid(&Usb); MyParser Parser; void setup() { FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // 初始化所有LED灯 FastLED.setBrightness( BRIGHTNESS ); Serial.begin( 115200 ); Serial.println("Start"); if (Usb.Init() == -1) { Serial.println("OSC did not start."); } delay( 200 ); Hid.SetReportParser(0, &Parser); } void loop() { Usb.Task(); } </c> ==20190103== <c> #include <usbhid.h> #include <usbhub.h> #include <hiduniversal.h> #include <hidboot.h> #include <SPI.h> #include <FastLED.h> #define NUM_LEDS 60 // led灯数量 #define DATA_PIN 6 // 数据传输引脚(Digital 6) #define BRIGHTNESS 25 ////設定led亮度 String s; CRGB leds[NUM_LEDS]; class MyParser : public HIDReportParser { public: MyParser(); void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); protected: uint8_t KeyToAscii(bool upper, uint8_t mod, uint8_t key); virtual void OnKeyScanned(bool upper, uint8_t mod, uint8_t key); virtual void OnScanFinished(); }; MyParser::MyParser() {} void MyParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { // If error or empty, return if (buf[2] == 1 || buf[2] == 0) return; for (uint8_t i = 7; i >= 2; i--) { // If empty, skip if (buf[i] == 0) continue; // If enter signal emitted, scan finished if (buf[i] == UHS_HID_BOOT_KEY_ENTER) { OnScanFinished(); } // If not, continue normally else { // If bit position not in 2, it's uppercase words OnKeyScanned(i > 2, buf, buf[i]); } return; } } uint8_t MyParser::KeyToAscii(bool upper, uint8_t mod, uint8_t key) { // Letters if (VALUE_WITHIN(key, 0x04, 0x1d)) { if (upper) return (key - 4 + 'A'); else return (key - 4 + 'a'); } // Numbers else if (VALUE_WITHIN(key, 0x1e, 0x27)) { return ((key == UHS_HID_BOOT_KEY_ZERO) ? '0' : key - 0x1e + '1'); } if(key== 55 ) { return 46; }else return 0; } void MyParser::OnKeyScanned(bool upper, uint8_t mod, uint8_t key) { uint8_t ascii = KeyToAscii(upper, mod, key); // Serial.print((char)ascii); delay(100); s= s + ((char)ascii) + ""; //s=s + ascii; } void MyParser::OnScanFinished() { float a=s.toFloat(); a=a*60; int uplimit=ceil(a)-1; int downlimit=floor(a)-1; Serial.println(uplimit); FastLED.clear(); if(uplimit==downlimit){ leds[uplimit] = CRGB::White; }else{ leds[uplimit] = CRGB::Red; // 设置第1个led灯的颜色Red leds[downlimit] = CRGB::Green; // 设置第2个led灯的颜色Red } FastLED.show(); s=""; } USB Usb; USBHub Hub(&Usb); HIDUniversal Hid(&Usb); MyParser Parser; void setup() { FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // 初始化所有LED灯 FastLED.setBrightness( BRIGHTNESS ); Serial.begin( 115200 ); Serial.println("Start"); if (Usb.Init() == -1) { Serial.println("OSC did not start."); } delay( 200 ); Hid.SetReportParser(0, &Parser); } void loop() { Usb.Task(); } </c>
返回到「
裁線條碼亮燈
」。
導覽選單
個人工具
建立帳號
登入
命名空間
頁面
討論
臺灣正體
視圖
閱讀
檢視原始碼
檢視歷史
更多
搜尋
導覽
首頁
近期變更
隨機頁面
MediaWiki說明
工具
連結至此的頁面
相關變更
特殊頁面
頁面資訊