跳到主要內容

發表文章

目前顯示的是 2015的文章

Arduino 切換開關點亮 LED - 處理 Bounce 問題

原來機械式開關還存在所謂的「彈跳 (Bounce)」問題 解決方式: 1. 延遲時間 (輪詢式) 2. 使用程式庫 Bounce2       官方出了新版的 library Bounce2      參考官方文件作法,調整為 #include <Bounce2.h> #define SERIAL_BAUDRATE 19200 #define LED_PIN 11 #define SWITCH_PIN 7 Bounce bouncer = Bounce(); boolean led_status; void setup() {   Serial.begin(SERIAL_BAUDRATE);   pinMode(LED_PIN, OUTPUT);   pinMode(SWITCH_PIN, INPUT);   // After setting up the button, setup the object   bouncer.attach(SWITCH_PIN);   bouncer.interval(5);      led_status = LOW;   digitalWrite(LED_PIN, led_status); } void loop() {      if(bouncer.update() == true && bouncer.read() == HIGH){     led_status = !led_status;     digitalWrite(LED_PIN, led_status);   } } 3. 延遲時間 (硬體中斷) 參考資料: 1. Arduino 輕鬆入門-範例分析與實作設計  葉難 著  博碩  2015.07 初版3刷 !!! 支持台灣本土作者、支持 TAAZE 讀冊生活 !!!

Arduino 切換開關點亮 LED - 未處理 Bounce 問題前

沒玩過不知道,原來我以為按下開關就好啦,想不到,我以為的「按一下」,在微控制器的角度來看,它已經呼叫 function 執行了好幾次。 參考資料: 1. Arduino 輕鬆入門-範例分析與實作設計  葉難 著  博碩  2015.07 初版3刷 !!! 支持台灣本土作者、支持 TAAZE 讀冊生活 !!!

My First Arduino Hello World ~

Arduino 的 Hello World 練習 讓小小的 LED 燈,一閃一閃~ 影片連結 在此

Google Maps API

最近同事遇到有關 Google Maps API 的問題,其中一個 marker cluster 的用法,在大量的產生 marker 時,會有 performance 的問題。找到下列兩篇資料留存參考 1.  https://developers.google.com/maps/articles/toomanymarkers 2. http://www.svennerberg.com/2009/01/handling-large-amounts-of-markers-in-google-maps/ 第二篇的作者把全部跟 GOOGLE MAPs API 有關的套件都測試過了,其中他推薦用 MarkerClusterer。

Git - Formatting Log Output

Graphs The  --graph  option draws an ASCII graph representing the branch structure of the commit history. This is commonly used in conjunction with the  --oneline  and  --decorate  commands to make it easier to see which commit belongs to which branch: git log --graph --oneline --decorate For a simple repository with just 2 branches, this will produce the following: * 0e25143 (HEAD, master) Merge branch 'feature' |\ | * 16b36c6 Fix a bug in the new feature | * 23ad9ad Start a new feature * | ad8621a Fix a critical security issue |/ * 400e4b7 Fix typos in the documentation * 160e224 Add the initial code base The asterisk shows which branch the commit was on, so the above graph tells us that the  23ad9ad  and  16b36c6  commits are on a topic branch and the rest are on the  master  branch. While this is a nice option for simple repositories, you’re probably better off with a more full-featured visualization tool ...

picamera - Recording video to a stream

import io import picamera stream = io.BytesIO() with picamera.PiCamera() as camera:     camera.resolution = (320, 240)     camera.start_recording(stream, format='h264', quality=30)     camera.wait_recording(10)     camera.stop_recording()

pi camera - take a picture (using python)

import time import picamera with picamera.PiCamera() as camera:     camera.resolution = (320, 240)     camera.start_preview()     time.sleep(2)     camera.capture('foo.jpg')

Accessing the Webcam with Python - Ubuntu

To install SimpleCV for python you'll need to start by installing the other libraries it depends on. Use apt-get:  ~ $ sudo apt-get install python-opencv python-scipy python-numpy python-pip Next, ~ $ sudo pip install https://github.com/ingenuitas/SimpleCV/zipball/master Next, ~ $ vim simplewebcam.py put the following code in it and save. from SimpleCV import Camera, Display from time import sleep myCamera = Camera(prop_set={'width':640,'height':480}) myDisplay = Display(resolution=(640,480)) while not myDisplay.isDone():    myCamera.getImage().save(myDisplay)    sleep(.1) ~ $ python simplewebcam.py then you can see the screen pop-out  

How to query mongodb with “like”?

db.users.insert({name: 'paulo'}) db.users.insert({name: 'patric'}) db.users.insert({name: 'pedro'}) db.users.find({name: /a/})  //like '%a%' out: paulo, patric db.users.find({name: /^pa/}) //like 'pa%' out: paulo, patric db.users.find({name: /ro$/}) //like '%ro' out: pedro Multiline Match for Lines Starting with Specified Pattern The following example uses the  m  option to match lines starting with the letter  S  for multiline strings: db . products . find ( { description : { $regex : /^S/ , $options : 'm' } } ) The query matches the following documents: { "_id" : 100 , "sku" : "abc123" , "description" : "Single line description." } { "_id" : 101 , "sku" : "abc789" , "description" : "First line\nSecond line" } Without the  m  option, the query would match just the follo...

刪除 iptables 裡的規則

1. 找出行號,方便刪除 root@cw2-netflow:~# iptables -L --line-numbers Chain INPUT (policy ACCEPT) num  target     prot opt source               destination         1    sshguard   all  --  anywhere             anywhere             Chain FORWARD (policy ACCEPT) num  target     prot opt source               destination         Chain OUTPUT (policy ACCEPT) num  target     prot opt source               destination         Chain sshguard (1 references) num  target     prot opt source       ...