研究筆記-LightBlue Bean+

最後編輯:2017-01-11 建立:2017-01-07 歷史紀錄

 

WUULONG S

緣起

很久以前看這個板子的介紹就很喜歡,主要是可以透過 藍芽升級 Arduino code.年前為了免運,順便敗了這個。

 

    蕭向廷Learn Check List

  • WUULONG SSetup
  • Program
  • Run most sample codes
  • Run demo mobile App
  • iBeacon checked

Hint

Cannot find bean’s serial port in Arduino IDE

  • To work around: cat /tmp/cu.LightBlue-Bean
  • screen /tmp/cu.LightBlue-Bean 9600

 

Battery Status

The current battery voltage is: 3.05V

The remaining battery life is: %70

 

小品分享

  • 研究板子中,突然有人需要一個功能,剛好用這個板子做很有趣。隨手就做了一個

 

  • 需求:八個外部按鈕,按下第一個按鈕,當作鍵盤敲下 '1', 其餘類推。按鈕跟電腦有點距離,不適合接線。
  • 作法:板子 GPIO0-7, 連接按鈕接地。板子模擬當成藍牙鍵盤,當判斷按鈕被按過,就輸出 Keycode 給遠端電腦。
  • 結果:如 code, 能基本運作,只能說板子太強大好用了,半小時完成的東西,就別要求細節了。
  • /*
  • * Main logic: press GPIO_0 , send keycode '1' to PC, GPIO_n -> keycode n+1'
  • * GPIO setup as default PULLUP, suggest to connect to GND
  • * Hardcode support GPIO 0-7
  • */
  • void setup() {
  • BeanHid.enable();
  • // Serial port is initialized automatically; we don't have to do anything
  • Serial.begin();
  • int i;
  • for(i=0;i<8;i++){
  • pinMode(i, INPUT_PULLUP);
  • }
  • }
  • int id_down_cur=-1; // current gpio id pressing
  • // return >=0 if One button released, default return -1
  • int GetButtonPressId(){
  • int i,value;
  • if(id_down_cur>=0){
  • value = digitalRead(id_down_cur);
  • if(value==1){
  • //Bean.setLed(0, 255, 0);
  • return id_down_cur;
  • }
  • }
  • for(i=0;i<8;i++){
  • value = digitalRead(i);
  • if(value==0) {
  • id_down_cur=i;
  • //Bean.setLed(255, 0, 0);
  • }
  • }
  • return -1;
  • }
  • void loop() {
  • int gpioid;
  • char c;
  • gpioid = GetButtonPressId();
  • if( gpioid>=0 ) {
  • c = 0x31+gpioid;
  • //Serial.println(c);
  • id_down_cur = -1;
  • BeanHid.sendKey(c);
  • Bean.sleep(50); // try to protect input variant from button
  • }
  • Bean.sleep(10);
  • }

參考